Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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!


One 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.


Wrong for some problem spaces, very right for others. There are many problem domains, and no tool right for all of them.


Very 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.


The 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.


You 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.


That works great if you're only using one interface in your class. What if you need to include two?


Then you use a different reuse strategy, like composition. The language is not ideal in this regard, certainly.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: