[Via Joel on Software] Folks that have been discussing code generation over on the Joel on Software forums pointed to a design pattern called Generation Gap, that was written up by John Vlissides that never made it into Design Patterns.
I don’t use subclassing to do delegation; instead I call a static method on another class. For example:
public void MyGeneratedMethod( int arg1, float arg2, Stream arg3 ) { MyDelegatedClass.MyDelegatedMethod( this, arg1, arg2, arg3 ); }
I believe that my approach is more flexible in that I can delegate at any point in a class hierarchy, not just at the leaf nodes. The downside is that this can sometimes break encapsulation in systems that don’t support the notion of internal visibility.
2 archived reader comments
Andy Hopper (2003-05-13)
OK. I’m drinking this Kool-Aid. I have modified my schema to support delegated persistence, and it works a charm, especially in Visual Studio (F12 puts your implementation a keystroke away!). It’s a nice compromise for when you can’t automatically generate 100% of the code.
Mike Griffin (2004-07-07)
MyGeneration comes with a free .NET architecture called dOOdads that specifically supports this deriviation technique, you never touch the generated code but inherit and override, see - http://www.mygenerationsoftware.com/