3 ms·
This is an awesome pattern. Seems like it could easily be added as a language feature to Java and C#. Add an alternative to the "virtual" keyword called "extens
by _bxg1 9y ago
This is an awesome pattern. Seems like it could easily be added as a language feature to Java and C#. Add an alternative to the "virtual" keyword called "extensible", and an alternative to "override" called "extend".
- masklinn 9y agoIsn't it pretty trivial to implement? Define an "inner" interface, set up the "outer" object with a default implementation (available to caller so they can wrap it rather than replace it entirely) and the "inner" calls simply delegate to it. Make all classes involved sealed/final. The degenerate case is the humble callback.
- icebraining 9y agoIsn't that essentially the onRender() solution they give in the article?
- emsy 9y agoThat’s basically the template method pattern and I remember some Windows API using it (maybe GDI) where the protected overridable method was called DrawInternal and the public Draw method was non-virtual.
- repsilat 9y agoIn fact, depending on whether the delegated methods depend on (protected) super-class state, this is probably better served with composition than inheritance.