Composite Pattern and simplificaton

JS js.mdnq at gmail.com
Wed Jul 3 13:34:52 PDT 2013


On Wednesday, 3 July 2013 at 10:41:02 UTC, Dicebot wrote:
> On Wednesday, 3 July 2013 at 10:12:34 UTC, JS wrote:
>> ...
>
> class A
> {
>     B b;
>     alias b this;
> }
>
> ?

Sorry, I left out one important detail, B is an interface so A 
has to implement B's methods. If B were class then this would not 
be a problem and alias this would not be required, and I could 
easily override any implementation details.

interface B { void foo(); }

class A : B { B b; void foo() { return b.foo(); } }

For each method in B, I have to write a duplicate method in A 
that redirects to b. I do not want to do this and I also want to 
partially implement B explicitly.

I think a mixin and traits could be used, at least to implicitly 
implement all of B, but I'm not sure about only partially.


More information about the Digitalmars-d mailing list