digitalmars.D - Interfaced programming - InterfacedProgramming.doc
- gediminasb pmt.lt (530/530) Jun 30 2005 Interfaced programming
- Regan Heath (34/69) Jun 30 2005 What's wrong with this:
- gediminasb pmt.lt (25/101) Jun 30 2005 Try to expand your example to class with two different LARGE interfaces:
- Chris Sauls (31/58) Jun 30 2005 Actually... no, no stubs needed. The abstract-superparent and mixin-tem...
- Regan Heath (7/127) Jun 30 2005 If you simply want something to provide stubs so as you can fill in the ...
- pragma (31/34) Jun 30 2005 Yes, but then the authors of Java came along and decided that the Adapte...
Interfaced programming Using interfaces in enterprise programming has one big issue: you must to write an implementation of methods in every class that implement this interface. This complicates software supporting in case of large set of classes where the interface is implemented. It would be nice to have one unit with implementation of the interface and use it in every class that implements this interface, but this trick is forbidden in D language. Constructors of Delphi language met the same problem and provided an elegant solution: they extended the language with implements directyve: property MyInterface: ImyInterface read FMyInterface implements IMyInterface; Compiler forwards myMethod(…) call to FmyInterface. myMethod(…) when myMethod(…) is member of ImyInterface. You should implement something similar like this. Here is one of possible solutions: o Programmer creates a class or class template that implements ImyInterface in separate unit, myImplementationClass, for example. o In every class that is going to implement ImyInterface, programmer declares state variable of myImplementationClass with implements directive: MyImplementationClass xVar implements ImyInterface; o Compiler will forward every ImyInterface call to inner variable xVar. This solution does not require large modifications and will provide very powerful tool for enterprise programming, especially combining it with class templates. Gediminasb Bukauskas gediminasb pmt.lt begin 0644 InterfacedProgramming.doc M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M_______________________LI<$`32`)!```\!*_````````$```````!``` ME0D```X`8FIB:N(]XCT````````````````````````)!!8`+A8``(!7``"` M````< $``'(!````````< $```````!R`0```````'(!````````< $``!0` M````````0PX``"0```#T#P``(`(``!02``!0`0``9PX``!4````````````` M````````````< $```````!0`P````````````````````````````!0`P`` M``"F!````````*8$````````I 0```````!0`P``[ ```'(!````````4`,` M```````````````````````````````````````````````````````````` M``!`````< $```````!R`0`````````````````````````````````````` M````````````````````````````````````````````00X```````!0`P`` M``````"&`0```````'(!````````< $```````!R`0```````'(!```````` M<R!I;B!E;G1E<G!R:7-E('!R;V=R86UM:6YG(&AA<R!O;F4 8FEG(&ES<W5E M.B!Y;W4 ;75S="!T;R!W<FET92!A;B!I;7!L96UE;G1A=&EO;B!O9B!M971H M;V1S(&EN(&5V97)Y(&-L87-S('1H870 :6UP;&5M96YT('1H:7, :6YT97)F M86-E+B!4:&ES(&-O;7!L:6-A=&5S('-O9G1W87)E('-U<'!O<G1I;F< :6X M8V%S92!O9B!L87)G92!S970 ;V8 8VQA<W-E<R!W:&5R92!T:&4 :6YT97)F M86-E(&ES(&EM<&QE;65N=&5D+B!)="!W;W5L9"!B92!N:6-E('1O(&AA=F4 M;VYE('5N:70 =VET:"!I;7!L96UE;G1A=&EO;B!O9B!T:&4 :6YT97)F86-E M(&%N9"!U<V4 :70 :6X 979E<GD 8VQA<W, =&AA="!I;7!L96UE;G1S('1H M:7, :6YT97)F86-E+"!B=70 =&AI<R!T<FEC:R!I<R!F;W)B:61D96X :6X M1"!L86YG=6%G92X-0V]N<W1R=6-T;W)S(&]F($1E;'!H:2!L86YG=6%G92!M M970 =&AE('-A;64 <')O8FQE;2!A;F0 <')O=FED960 86X 96QE9V%N="!S M;VQU=&EO;CH =&AE>2!E>'1E;F1E9"!T:&4 ;&%N9W5A9V4 =VET:"!I;7!L M;G1E<F9A8V4-<F5A9"!&37E);G1E<F9A8V4 :6UP;&5M96YT<R!)37E);G1E M($9M>4EN=&5R9F%C92X ;7E-971H;V0HA2D =VAE;B!M>4UE=&AO9"B%*2!I M<R!M96UB97( ;V8 26UY26YT97)F86-E+ T-66]U('-H;W5L9"!I;7!L96UE M;G0 <V]M971H:6YG('-I;6EL87( ;&EK92!T:&ES+B!(97)E(&ES(&]N92!O M87-S(&]R(&-L87-S('1E;7!L871E('1H870 :6UP;&5M96YT<R!);7E);G1E M<F9A8V4 :6X <V5P87)A=&4 =6YI="P ;7E);7!L96UE;G1A=&EO;D-L87-S M+"!F;W( 97AA;7!L92X-26X 979E<GD 8VQA<W, =&AA="!I<R!G;VEN9R!T M;R!I;7!L96UE;G0 26UY26YT97)F86-E+"!P<F]G<F%M;65R(&1E8VQA<F5S M(&EM<&QE;65N=', 9&ER96-T:79E. U->4EM<&QE;65N=&%T:6]N0VQA<W, M>%9A<B!I;7!L96UE;G1S($EM>4EN=&5R9F%C93L-0V]M<&EL97( =VEL;"!F M;W)W87)D(&5V97)Y($EM>4EN=&5R9F%C92!C86QL('1O(&EN;F5R('9A<FEA M9V4 ;6]D:69I8V%T:6]N<R!A;F0 =VEL;"!P<F]V:61E('9E<GD <&]W97)F M=6P =&]O;"!F;W( 96YT97)P<FES92!P<F]G<F%M;6EN9RP 97-P96-I86QL M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M$0 ``!X(``!:"```6P ``%\(``! "```: ``&L(``!V"```BP ``(P(``"0 M\.?PY_#G\.?;Y_#G\`#P`/#G\.?PYP`````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M````````%C4( 4-*% !/2 ``44H``%P( 5Y*````$$-*% !/2 ``44H``%Y* M````!C4( 5P( 0`,0TH6`&U("01S2`D$``AM2`D$<T )!"0`!```%P0``! $ M`*H(``#P M````````^0```````````````/L```````````````#S```````````````` M\P```````````````.D```````````````#G````````````````YP`````` M`````````.<```````````````#G````````````````X `````````````` M``````````#G````````````````YP```````````````.<````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M`0```1````D0``^$T`(1A-`"7H30`F"$T`(`!1``#X30`EZ$T`(``0\```$` M```!`0``$P`$``"5"0``_ `````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````"`0$!+``QD& !'[""+B"PQD$AL` '(K`( M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````4`!$` M" `!`&D`#P M``(````8`$-*&`!?2`$$84H8`&U("0AS2`D(=$ )!%(``4`!``(`4 `,``D` M(`!+2"``3TH"`%%*` !<"(%>2 (`84H ```````````````````````\`$%` M\O^A`#P M`$8`;P!N`'0`````````````````, !"8`$`\ `R``P`"0!"`&\`9`!Y`"`` M5`!E`' `=`````(`#P`,`$-*% !M2`D$<T )!$(`4&`!``(!0 `,``L`0 !O M\00``)(%``"4!0``EP4``` ````!,`````````"````` ) `````,``````` M``"``````) ````/,`````````"``````) `````,`````````"``````) ` M```0,`````````"``````) ````0,`````````"``````) ````0,``````` M``"``````) ````0,`````````"``````) ````0,`````````"``````) ` M```0,`````````"``````) ````0,`````````"``````) ``2`0,``````` M``"``````) ``2`0,`$```````"``````) ````0,`````````"``````) ` M`R`0,`````````"``````) ````0,`````````"````` ) ````0,``````` M``"````` ) ````0,`````````"````` ) ````0,`````````"````````$ M``"5"0``"``````$``"5"0``"0`````$``"5"0``" ````````!*` ``4P(` MUP(``-D"``#A M!```'00``$4$``!:!```= 0``(L$``",!```D`0``)P$``"H!```Q 0``-($ M``#J!```[ 0``)<%```'`!P`!P`<``<`'``'`!P`!P`<``<`'``'`!P`!P`< M``<`'``'`!P`!P`<``<`'``'`!P`!P`<``<`'``'`!P`!P`<``<`'``'`!P` M`'4`:P!A`'4`<P!K`&$`<P!J`$,`. !<`$0`;P!C`'4`;0!E`&X`=`!S`"`` M80!N`&0`(`!3`&4`=`!T`&D`; !G`',`7`!!`&0`;0!I`&X`:0!S`'0`< !A M`'0`;P!R`%P`00!P`'``;`!I`&,`80!T`&D`;P!N`"``1`!A`'0`80!<`$T` M:0!C`'(`;P!S`&\`9 !T`%P`5P!O`'(`9`!<`$$`=0!T`&\`4 !E`&,`;P!V M`&4`< !Y`"``<P!A`'8`90` `&\`9 ` `$0`;P!C`'4`;0!E`&X`=``Q`"X` M80!S`&0`$P!'`&4`9`!I`&T`:0!N`&$`<P` `$(`=0!K`&$`=0!S`&L`80!S M`"$`0P`Z`%P`=`!E`&T`<`!<`$D`; !T`&4`< !F`&$`8P!E`&0`4`!R`&\` M&```#X30 M`!>0`````````````& !````````"Q ```^$H`41A)C^%<8%``& !09>A*`% M8(28_D]*`P!12 ,`;R ``0!O``$````7D`````````````!H`0````````L8 M```/A'`($828_A7&!0`!<` &7H1P"&"$F/Y/2 0`44H$`&\H``$`I_`!```` M%Y``````````````:`$````````+&```#X1`"Q&$F/X5Q 4``4`+!EZ$0`M MA)C^3TH!`%%*`0!O*``!`+?P`0```!>0`````````````& !````````"Q ` MD`````````````!H`0````````L8```/A.`0$828_A7&!0`!X!`&7H3 $&"$ MF/Y/2 0`44H$`&\H``$`I_`!````%Y``````````````:`$````````+&``` M#X2P$Q&$F/X5Q 4``;`3!EZ$L!- A)C^3TH!`%%*`0!O*``!`+?P`0```!>0 M`````````````& !````````"Q ```^$ !81A)C^%<8%``&`% 9>A(`68(28 M_D]*`P!12 ,`;R ``0!O``$````7D`````````````!H`0````````L8```/ MA%`9$828_A7&!0`!4!D&7H10&6"$F/Y/2 0`44H$`&\H``$`I_`!````%Q`` M````````````:`$````````+&```#X0X!!&$F/X5Q 4``3 $!EZ$.`1 A)C^ M"`<1A)C^%<8%``$(!P9>A` '8(28_D]*`P!12 ,`;R ``0!O``$````7D``` M``````````!H`0````````L8```/A- )$828_A7&!0`!V`D&7H38"6"$F/Y/ M2 0`44H$`&\H``$`I_`!````%Y``````````````:`$````````+&```#X2H M`````````& !````````"Q ```^$>`\1A)C^%<8%``%X#P9>A' /8(28_D]* M`P!12 ,`;R ``0!O``$````7D`````````````!H`0````````L8```/A$ 2 M$828_A7&!0`!2!(&7H1($F"$F/Y/2 0`44H$`&\H``$`I_`!````%Y`````` M````````:`$````````+&```#X08%1&$F/X5Q 4``1 5!EZ$&!5 A)C^3TH! M`%%*`0!O*``!`+?P`0```!>0`````````````& !````````"Q ```^$Z!<1 MA)C^%<8%``'H%P9>A. 78(28_D]*`P!12 ,`;R ``0!O``$````7D``````` M``````!H`0````````L8```/A+ :$828_A7&!0`!N!H&7H2X&F"$F/Y/2 0` M44H$`&\H``$`I_`!````%Q``````````````:`$````````+&```#X30`A&$ M`````& !````````"Q ```^$H`41A)C^%<8%``& !09>A*`%8(28_D]*`P!1 M2 ,`;R ``0!O``$````7D`````````````!H`0````````L8```/A'`($828 M_A7&!0`!<` &7H1P"&"$F/Y/2 0`44H$`&\H``$`I_`!````%Y`````````` M````:`$````````+&```#X1`"Q&$F/X5Q 4``4`+!EZ$0`M A)C^3TH!`%%* M`0!O*``!`+?P`0```!>0`````````````& !````````"Q ```^$$`X1A)C^ M``!H`0````````L8```/A.`0$828_A7&!0`!X!`&7H3 $&"$F/Y/2 0`44H$ M`&\H``$`I_`!````%Y``````````````:`$````````+&```#X2P$Q&$F/X5 MQ 4``;`3!EZ$L!- A)C^3TH!`%%*`0!O*``!`+?P`0```!>0```````````` M`& !````````"Q ```^$ !81A)C^%<8%``&`% 9>A(`68(28_D]*`P!12 ,` M;R ``0!O``$````7D`````````````!H`0````````L8```/A%`9$828_A7& M``D$!0`)!!(``P`)!`,`"00%``D$`0`)!`,`"00%``D$`0`)!`,`"00%``D$ M`````````/__`0``````__\```(`__\`````__\```(`__\`````!0```$<6 MD`$```("! ,%!`4"`P2'> ` ```` ` `````````_P$```````!4`&D`;0!E M` ("` 2'> ` ```` ` `````````_P$```````!!`'(`:0!A`&P````_-9`! M```"!P,)` (%` 0$AWH`(````(`(`````````/\!````````0P!O`'4`< !I M`&4`< ` `$X`90!W````.P:0`0(`!0`````````````````````0```````` M``````"``````%<`:0!N`&<`9`!I`&X`9P!S````( `$`'$(B! `\-`"``!H M`0`````U\Y:&<_.6A `````!`#H M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M`````````````````````````````````` 'H`6T`+0` 8$R,``````````` M````````I 4````````````````````````````````````````````````` M`#H`7`!$`&\`8P!U`&T`90!N`'0`<P` `&$`; !D`"``4P!E`'0`=`!I`&X` M9P!S`%P`00!D`&T`:0!N`&D`<P!T`'(`80!T`&\`< !<`$$`<`!P`&P`:0!C M`&$`=`!I`&\`; ` `$0`80!T`&$`7`!-`&D`8P!R`&\`<P!O`&8`=`!<`%0` M90!M`'``;`!A`'0`90!S`%P`3 !O`'(`;0!A`&P`+ !D`&\`=``6`$D`; !T M`&4`< !F`&$`8P!E`&0`(`!P`'(`;P!G`'(`80!M`&T`:0!N`&<````````` M$P!'`&4`9`!I`&T`:0!N`&$`<P` `$(`=0!K`&$`=0!S`&L`80!S`!,`1P!E M`&0`:0!M`&D`; !A`',`(`!"`'4`:P!A`'4`<P!K`&$`<P`````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M`````````````````````````````````````````/[_```%``(````````` M`)`````"````F`````,```"X````!````,0````%````X`````8```#L```` M``#D!```' ```!<```!);G1E<F9A8V5D('!R;V=R86UM:6YG```>`````0`` M``!N=&4>````%````$=E9&EM:6YA<R!"=6MA=7-K87,`' ````$`````961I M' ````$`````961I' ````L```!.;W)M86PN9&]T`'4>````%````$=E9&EM M:6YA<R!"=6MA=7-K87,`' ````(````Q`&1I' ```!,```!-:6-R;W-O9G0 M5V]R9"`Y+C```$``````W#T:"````$``````IM)_67W%`4`````` A":87W% M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M``!H````#P```'`````%````A`````8```",````$0```)0````7````G``` M``L```"D````$````*P````3````M````!8```"\````" ```,0````,```` MYP````(```#D M````````'A````$````7````26YT97)F86-E9"!P<F]G<F%M;6EN9P`,$``` M` ```!X````&````5&ET;&4``P````$````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M````$````!$````2````$P```!0````5````_O___Q<````8````&0```!H` M`/[____]____*````/[____^_____O______________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M______]2`&\`;P!T`"``10!N`'0`< !Y```````````````````````````` M````````````````````````````````% `%`?__________`P````8)` `` M5`!A`&(`;`!E```````````````````````````````````````````````` M```````````````````````.``(`________________```````````````` M`&\`8P!U`&T`90!N`'0````````````````````````````````````````` M`````````````!H`` $%````__________\````````````````````````` M````````````````````````````+A8````````%`%,`=0!M`&T`80!R`'D` M20!N`&8`;P!R`&T`80!T`&D`;P!N```````````````````````````````` M````*``"`0(````$````_____P`````````````````````````````````` M`````````````!8`````$`````````4`1`!O`&,`=0!M`&4`; !T`%,`=0!M M`&T`80!R`'D`20!N`&8`;P!R`&T`80!T`&D`;P!N```````````````X``(! M________________```````````````````````````````````````````` M`````````````````````````````````````````````!(`` $!````! `` M`/____\````````````````````````````````````````````````````` M: ````````!/`&(`: !E`&,`=`!0`&\`;P!L```````````````````````` M````````````````````````````````````% `!`/_______________P`` M````````````````````````4%U!NV%]Q0%074&[87W%`0`````````````` M```````````````````````````````````````````````````````````` M````````````````````````````````________________```````````` M`````````````````````````````````````````````````````0```/[_ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M____________________________________________________________ M______________\!`/[_`PH``/____\&"0(``````,````````!&&````$UI M8W)O<V]F="!7;W)D($1O8W5M96YT``H```!-4U=O<F1$;V,`$````%=O<F0N M1&]C=6UE;G0N.`#T.;)Q```````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` M```````````````````````````````````````````````````````````` <```````````````````````````````````````` ` end
Jun 30 2005
What's wrong with this:
interface Bob
{
void foo();
}
abstract class aBob : Bob {
void foo() { printf("abstract\n"); }
}
template tBob() {
void foo() { printf("template\n"); }
}
class Fred : aBob {
}
class Carl {
mixin tBob;
}
class John : aBob {
override void foo() { printf("override\n"); }
}
void main()
{
Fred f = new Fred();
Carl c = new Carl();
John j = new John();
f.foo();
c.foo();
j.foo();
}
Fred uses an abstract class which contains the implementation. Carl uses a
mixin to mix a template containing the implementation. John uses the
abstract class but provides an override.
Regan
On Thu, 30 Jun 2005 10:52:26 +0000 (UTC), <gediminasb pmt.lt> wrote:
Interfaced programming
Using interfaces in enterprise programming has one big issue: you must
to write
an implementation of methods in every class that implement this
interface. This
complicates software supporting in case of large set of classes where the
interface is implemented. It would be nice to have one unit with
implementation
of the interface and use it in every class that implements this
interface, but
this trick is forbidden in D language.
Constructors of Delphi language met the same problem and provided an
elegant
solution: they extended the language with implements directyve:
property MyInterface: ImyInterface
read FMyInterface implements IMyInterface;
Compiler forwards myMethod(…) call to FmyInterface. myMethod(…) when
myMethod(…)
is member of ImyInterface.
You should implement something similar like this. Here is one of possible
solutions:
o Programmer creates a class or class template that implements
ImyInterface in
separate unit, myImplementationClass, for example.
o In every class that is going to implement ImyInterface, programmer
declares
state variable of myImplementationClass with implements directive:
MyImplementationClass xVar implements ImyInterface;
o Compiler will forward every ImyInterface call to inner variable xVar.
This solution does not require large modifications and will provide very
powerful tool for enterprise programming, especially combining it with
class
templates.
Gediminasb Bukauskas
gediminasb pmt.lt
Jun 30 2005
Try to expand your example to class with two different LARGE interfaces:
interface Bob
{
void foo1 ();
…
void foo100();
}
interface Smith
{
void fpp1():
…
void fpp100();
}
class Uncle1: Bob, Smith
{
…. ??? ….
}
class Uncle2: Bob, Smith
{
…. ??? ….
}
You must to provide stubs for 200 functions in every class that implement these
two interfaces! This is tedious and error prone work. Compiler will do it
better.
In article <opss6jr4mv23k2f5 nrage.netwin.co.nz>, Regan Heath says...
What's wrong with this:
interface Bob
{
void foo();
}
abstract class aBob : Bob {
void foo() { printf("abstract\n"); }
}
template tBob() {
void foo() { printf("template\n"); }
}
class Fred : aBob {
}
class Carl {
mixin tBob;
}
class John : aBob {
override void foo() { printf("override\n"); }
}
void main()
{
Fred f = new Fred();
Carl c = new Carl();
John j = new John();
f.foo();
c.foo();
j.foo();
}
Fred uses an abstract class which contains the implementation. Carl uses a
mixin to mix a template containing the implementation. John uses the
abstract class but provides an override.
Regan
On Thu, 30 Jun 2005 10:52:26 +0000 (UTC), <gediminasb pmt.lt> wrote:
Interfaced programming
Using interfaces in enterprise programming has one big issue: you must
to write
an implementation of methods in every class that implement this
interface. This
complicates software supporting in case of large set of classes where the
interface is implemented. It would be nice to have one unit with
implementation
of the interface and use it in every class that implements this
interface, but
this trick is forbidden in D language.
Constructors of Delphi language met the same problem and provided an
elegant
solution: they extended the language with implements directyve:
property MyInterface: ImyInterface
read FMyInterface implements IMyInterface;
Compiler forwards myMethod(…) call to FmyInterface. myMethod(…) when
myMethod(…)
is member of ImyInterface.
You should implement something similar like this. Here is one of possible
solutions:
o Programmer creates a class or class template that implements
ImyInterface in
separate unit, myImplementationClass, for example.
o In every class that is going to implement ImyInterface, programmer
declares
state variable of myImplementationClass with implements directive:
MyImplementationClass xVar implements ImyInterface;
o Compiler will forward every ImyInterface call to inner variable xVar.
This solution does not require large modifications and will provide very
powerful tool for enterprise programming, especially combining it with
class
templates.
Gediminasb Bukauskas
gediminasb pmt.lt
Jun 30 2005
gediminasb pmt.lt wrote:
Try to expand your example to class with two different LARGE interfaces:
interface Bob
{
void foo1 ();
…
void foo100();
}
interface Smith
{
void fpp1():
…
void fpp100();
}
class Uncle1: Bob, Smith
{
…. ??? ….
}
class Uncle2: Bob, Smith
{
…. ??? ….
}
You must to provide stubs for 200 functions in every class that implement these
two interfaces! This is tedious and error prone work. Compiler will do it
better.
Actually... no, no stubs needed. The abstract-superparent and mixin-template
methods
still work. Size makes no difference.
Or maybe one could create a templated parent to provide the interfaces and
their standard
implementations:
Or:
Using:
The only thing missing to make this method perfect, is variadic template
arguments, though
how exactly one would pull that off is beyond me.
-- Chris Sauls
Jun 30 2005
If you simply want something to provide stubs so as you can fill in the
contents (I can understand that), I'd suggest this was the job of a good
IDE. Otherwise mixins and abstract base classes still work. Abstract base
classes prevent inheritance from another class, so I tend to use mixins
the whole time.
Regan
On Thu, 30 Jun 2005 12:36:22 +0000 (UTC), <gediminasb pmt.lt> wrote:
Try to expand your example to class with two different LARGE interfaces:
interface Bob
{
void foo1 ();
…
void foo100();
}
interface Smith
{
void fpp1():
…
void fpp100();
}
class Uncle1: Bob, Smith
{
…. ??? ….
}
class Uncle2: Bob, Smith
{
…. ??? ….
}
You must to provide stubs for 200 functions in every class that
implement these
two interfaces! This is tedious and error prone work. Compiler will do it
better.
In article <opss6jr4mv23k2f5 nrage.netwin.co.nz>, Regan Heath says...
What's wrong with this:
interface Bob
{
void foo();
}
abstract class aBob : Bob {
void foo() { printf("abstract\n"); }
}
template tBob() {
void foo() { printf("template\n"); }
}
class Fred : aBob {
}
class Carl {
mixin tBob;
}
class John : aBob {
override void foo() { printf("override\n"); }
}
void main()
{
Fred f = new Fred();
Carl c = new Carl();
John j = new John();
f.foo();
c.foo();
j.foo();
}
Fred uses an abstract class which contains the implementation. Carl
uses a
mixin to mix a template containing the implementation. John uses the
abstract class but provides an override.
Regan
On Thu, 30 Jun 2005 10:52:26 +0000 (UTC), <gediminasb pmt.lt> wrote:
Interfaced programming
Using interfaces in enterprise programming has one big issue: you must
to write
an implementation of methods in every class that implement this
interface. This
complicates software supporting in case of large set of classes where
the
interface is implemented. It would be nice to have one unit with
implementation
of the interface and use it in every class that implements this
interface, but
this trick is forbidden in D language.
Constructors of Delphi language met the same problem and provided an
elegant
solution: they extended the language with implements directyve:
property MyInterface: ImyInterface
read FMyInterface implements IMyInterface;
Compiler forwards myMethod(…) call to FmyInterface. myMethod(…)
when
myMethod(…)
is member of ImyInterface.
You should implement something similar like this. Here is one of
possible
solutions:
o Programmer creates a class or class template that implements
ImyInterface in
separate unit, myImplementationClass, for example.
o In every class that is going to implement ImyInterface, programmer
declares
state variable of myImplementationClass with implements directive:
MyImplementationClass xVar implements ImyInterface;
o Compiler will forward every ImyInterface call to inner variable xVar.
This solution does not require large modifications and will provide
very
powerful tool for enterprise programming, especially combining it with
class
templates.
Gediminasb Bukauskas
gediminasb pmt.lt
Jun 30 2005
In article <da0ita$qv8$1 digitaldaemon.com>, gediminasb pmt.lt says...Interfaced programming[snip]Constructors of Delphi language met the same problem and provided an elegant solution: they extended the language with implements directyve:Yes, but then the authors of Java came along and decided that the Adapter pattern is good enough. Also, D has a habit of trapping mistakes, and making lots of noise about them when it sees them, and halting compilation/execution if that's the case. This feature seems to go against the grain with that notion. (I don't know how experienced you are with software engineering, so I apologize in advance if this all old news. There are some neophytes in this NG, so I'm writing this largely for their reading.) Now we're not writing in Java, but when you get down to it: implementing an interface really should involve completely *supporting* that interface. Its something that transcends any language, and can be found in just about any textbook on OOP. Otherwise, you're really trying to provide boilerplate code as a shortcut. Adapters, and multiple-inheritance thereof (using mixins in D), do a good job of supporting this need. I'll add that if you have an interface that one would only need to partially support, it could arguably be split into multiple interfaces instead. Good design dictates that an interface's purpose should be more or less orthogonal to other interfaces (unless they inherit each other). This also has implications for cooperative development, where author A changes an interface and author B uses the modified version in his/her code. Author B will now have (silently) buggy code without even so much as a peep from the compiler. I have seen older renditions of DMD cause a cast to an interface (under certain conditions) to return a vtable of seemingly 'empty' methods. My funcion calls were going into oblivion with no warning, contrary to the code. Even after I deduced what was going on, it was still a huge source for bugs and error in my program. I could expect the same kind of frustration were D augmented in the way you suggest, as now I will have no warning if I have forgotten to implement a particular method. - EricAnderton at yahoo
Jun 30 2005









Chris Sauls <ibisbasenji gmail.com> 