“Favor composition over inheritance” is a phrase that I hear spoken a lot but which describes a concept I rarely actually see in real world code. Every developer seems to know about it but few developers seem to actually put it into practice. This post will be looking at inheritance and some of the pitfalls of trying to create your domain model primarily through inheritance.
I can only assume that the reason why inheritance is so overused in real world code is due to the way that it is taught. Back, far too many years ago, while I was still studying at university, the concepts of inheritance and polymorphism where both taught side by side, very early in the object oriented programming course. It seems as though these lessons were particularly memorable, because so much real-world code has giant inheritance chains. We have ObscuredItems inheriting from DataItems inheriting from BasicItems…
View original post 755 more words