3 ms·
Interfaces are types, and concrete classes implementing them are subtypes. OTOH, it's probably easier to avoid LSP violations with interfaces than concrete sup
by dragonwriter 7y ago
Interfaces are types, and concrete classes implementing them are subtypes.
OTOH, it's probably easier to avoid LSP violations with interfaces than concrete supertypes.
> Is there a good reason to have a class hierarchy in modern programming?
Well, implementation inheritance facilitates code reuse; there's some ways to do that that aren't traditional class heirarchies, but they mostly seem morally equivalent to multiple inheritance with partially-abstract base classes. Ergonomically, though, I think some of them don't do as much to encourage inappropriate subytyping or implementation sharing compared to classical purely-class-based inheritance.
- yann-gael 7y agoYes, that's the reason why it is important to distinguis h between types and implementation classes. Types should describe a taxonomy of "things" as well as possible and according to the need of the client. Implementation classes should be used to reuse/factor out as much code as possible (DRY) while providing implementations for the types. Java interfaces are nice because they can be used as types while one or many classes can implement them.