开发者

Is there an OOP principle against a concrete class extending another concrete class?

开发者 https://www.devze.com 2023-01-14 18:36 出处:网络
I have read that this should be avoided, though I can\'t recall the source. Inheritance should used with abstrac开发者_StackOverflowt classes in the middle of the hierarchy, and concrete classes showi

I have read that this should be avoided, though I can't recall the source. Inheritance should used with abstrac开发者_StackOverflowt classes in the middle of the hierarchy, and concrete classes showing only as leaves.

Where can I find a good explanation of the reasoning behind this? (Opposite opinions are also welcome)


This shouldn't be taken too strictly. I think the underlying idea is more to focus on programming to an interface, either a pure interface or an abstract class, as this enables looser coupling of your design, polymorphism, encapsulation,...

Also mind to not violate the Liskov substitution principle

0

精彩评论

暂无评论...
验证码 换一张
取 消