3 ms·
One of the fundamental principles of OO is go for interface inheritance(design) as opposed to class inheritance(implementation). Better way to enable code reuse
by anuraj 14y ago
One of the fundamental principles of OO is go for interface inheritance(design) as opposed to class inheritance(implementation). Better way to enable code reuse is through association. That is why languages like Java do not allow multiple class inheritance, but allow you to inherit from multiple interfaces. You are doing it the wrong way!
- JoeAltmaier 14y agoWrong for some problem spaces, very right for others. There are many problem domains, and no tool right for all of them.
- anuraj 14y agoVery right. It is about how you think in terms of OO. If you feel the problem space cannot be modeled easily, just don't go for OO. That said, many problem spaces are amenable to OO thinking. But some are not (especially the ones that deal with serial hardware interfaces), just go for procedural thinking in these cases.
- colomon 14y agoThe problem is you really want to inherit the implementations as well -- otherwise every one of the classes that use the Isin interface must implement its storage and accessors as well.
- gboyer 14y agoYou can just do both, though. Use interfaces for polymorphism, to define the interactions between your objects -- and then, if you want, use inheritance as one possible strategy for code reuse.
- deleted 14y ago[deleted]
- eli_gottlieb 14y agoOne of the fundamental principles of OO is go for interface inheritance(design) as opposed to class inheritance(implementation). That wasn't a "fundamental principle of OO" until halfway through the 2000s.