Skip to main content
18 events
when toggle format what by license comment
Jul 1, 2017 at 2:42 comment added Dave Cousineau Abstract classes, as you say, are tied to implementation. For this reason, while you can put some implementation into an abstract class, one should strongly avoid ever referring to the abstract class and instead use an interface. Otherwise you are coupling your code to the implementation that is in the abstract class.
Oct 28, 2014 at 1:35 comment added deadalnix It indeed replace the need for abstract classes in various scenarios. More specifically, it remove the need of abstract classes to avoid code duplication.
Oct 20, 2014 at 12:32 comment added raptortech97 Java now has default implementations for interfaces. Does that change the answer?
Oct 7, 2011 at 6:09 comment added Gulshan In C#, we have extension methods attached with interfaces. And this pattern is extensively used in Linq provider libraries.
Jul 25, 2011 at 9:56 comment added deadalnix Then this is not that pattern, but another.
Jul 23, 2011 at 17:35 comment added Joh "Without abstract method/classes, you cannot implement template method pattern". Yes you can, just pass the code to put in the hole using a function object, a function pointer, a delegate, a function value...
Jul 22, 2011 at 10:02 comment added deadalnix I'm not saying that it's the best. I'm saying that it's a way that work. The best way will always depends on what you face. Pattern like strategy or state does the trick too, but complexify instanciation of the object. So this is up to the developper to know what is the best depending of the situation. And yes sequential coupling MUST be reduced. Reduced doesn't mean suppressed. It just means that this is usually the sign of a badly designed interface, and the cases where it's good are exceptions.
Jul 22, 2011 at 7:30 comment added back2dos @deadalnix: Saying that sequential coupling is best reduced with the template pattern is cargo cult programming (using the state/strategy/factory pattern may just work as well), as is the assumption that it must always be reduced. Sequential coupling is often a mere consequence of exposing very fine grained control over something, meaning nothing but a trade-off. That still doesn't mean I can't write a wrapper that does not have sequential coupling using composition. In fact, it makes it a lot easier.
Jul 21, 2011 at 22:05 comment added Joseph Weissman For what it's worth, I use both all the time. They're different tools...
Jul 21, 2011 at 21:27 comment added deadalnix This doesn't explain AT ALL how to reduce sequential coupling. I do agree that several ways exists to achieve this goal, but please, answer the problem you are talking about instead of blindly invoke some principle. You'll ends up doing cargo cult programming if you can't explain why this is related to the actual problem.
Jul 21, 2011 at 21:17 comment added back2dos This seems more like an anti-pattern. You can get exactly the same thing with composition against an interface. Same thing applies to partial classes with some abstract methods. Rather then forcing client code to subclass and override them, you should have the implementation be injected. See: en.wikipedia.org/wiki/Composition_over_inheritance#Benefits
Jul 21, 2011 at 21:15 comment added deadalnix @quant_dev patterns has a purpose. Using it when it's not appropriate leads to bad code. That obvious and not related to that pattern. If you put pattern everywhere when they shouldn't be used, you end up with bloated code which is almost impossible to understand.
Jul 21, 2011 at 18:51 comment added YetAnotherUser +1 - Also - Abstract Class is defining the 'structure' of your would_be concrete class where as Interface is defining the 'behaviour', I would say this is pretty strong reason in itself.
Jul 21, 2011 at 17:20 comment added quant_dev @deadalnix Template method pattern can be quite dangerous. You can easily end up with highly coupled code, and start hacking the code to extend the templated abstract class to handle "just one more case".
Jul 21, 2011 at 17:14 vote accept Boris Yankov
Jul 21, 2011 at 17:14 comment added Boris Yankov So.. funny thing. I wasn't sure what the Template Method pattern is. And the question steamed up from my implementation of it with abstract classes. Too much of a coincidence? :)
Jul 21, 2011 at 16:37 comment added Alex Feinman @wolfgangsz, you can't, but collectively we can. ;)
Jul 21, 2011 at 15:46 history answered deadalnix CC BY-SA 3.0