I recently had a small "argument" about inheritance with a friend. I think people overuse it a lot. Intuition tells me that that the only good reason for class inheritance is polymorphism - when there is a case that you want to treat uniquely object of different but related classes.
Our argument was about having a BaseEntity class for Entity Framework that only has Id property. My friend says it's good because he can have generic repositories then. W don't agree with him.
- Usually there's no such thing as a generic repository, you'll end up with "Refused bequest" smell.
- What's the point of treating let's say a user and an invoice uniquely? These are 2 totally different things.
Unfortunately I couldn't make any good points in spite of "it makes no sense". :)
After a while I also realized that I drifted away from inheritance itself and now I tend to use interfaces instead. Actually in my recent web project (quite a big one) I can't recall any inheritance. Now I'm not sure when it is an appropriate technique anymore.
So guys, please help me here.
- What do you think about what I wrote?
- Can you find any arguments I can use against my friend?
- When it really is a good practice to use inheritance? (Please be specific and throw some examples)
Please don't try to explain to me what the inheritance is all about. I'm very familiar with that and I used it a lot. Like I mentioned above, over time I just drifted away from it, because I couldn't find the right usage for it. Simply interfaces seem to be a better approach to me in most cases.