Your polymorphism example breaks the Liskov substitution principle. Just use composition and don't make cow1 instanceof Dog === true 🤦♂️ Did you study biology basics? 😉
You're welcome. Just didn't want to write that the example missed the point completely, that's all. 🤷♂️ But you're definitely on a good path, keep going!
Principle are "stuff that helps more often than not", not pervasive absolutes on the same level as God's word. But more to the point, it would be weird to talk about inheritance as a "pillar" of oop when general practices have been recommending composition over inheritance for years.
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Your polymorphism example breaks the Liskov substitution principle. Just use composition and don't make
cow1 instanceof Dog === true
🤦♂️ Did you study biology basics? 😉My bad, changed it to inherit from the Animal class. You happy now professor?
You're welcome. Just didn't want to write that the example missed the point completely, that's all. 🤷♂️ But you're definitely on a good path, keep going!
Principle are "stuff that helps more often than not", not pervasive absolutes on the same level as God's word. But more to the point, it would be weird to talk about inheritance as a "pillar" of oop when general practices have been recommending composition over inheritance for years.