Streams: an open discussion
    Sean Kelly 
    sean at f4.ca
       
    Wed Mar 15 23:59:25 PST 2006
    
    
  
surferjeff at excite.com wrote:
> 
> I see. Not so bad.  Thanks.
> 
> Instead of the "Inherit 20 methods, implement 3 pure virtual methods" approach,
> how about "implement the same 3 pure virtual methods in an interface, pass the
> interface to a class that uses it to implement the 20 methods."  I've used the
> former pattern a lot in C++, and have found it difficult to reuse.  I recently
> learned the latter pattern in Objective-C and Cocoa, and have found it much
> easier to reuse.
Something like:
     class MyStreamImpl()
     {
         void readBlock();
         void writeBlock();
         seek();
     }
     class Stream( Impl )
     {
         mixin Impl!() impl;
         alias impl.readBlock readBlock;
         alias impl.writeBlock writeBlock;
         alias impl.seek seek;
         ...
     }
     alias Stream!(MyStreamImpl) MyStream;
Sean
    
    
More information about the Digitalmars-d
mailing list