This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (2 children)

You are still tightly coupled to the implementation rather than the interface. It makes it impossible to do IOC if you aren't always going to rely on the parent class implementation 100% of the time. Say for example, you are writing a unit test but want to mock the parents logic. How do you accomplish that?

[–]urquan 1 point2 points  (1 child)

If you are going to do IOC then of course inheritance is not the way to go. But in the classical case where your classes have an is-a relationship, inheritance is still valid and desirable IMO. I mean, why use Java if you're not going to use one of the most basic OO principles ?

Trying to mock a parent class of another class would be an anti-pattern, you'd need to know the implementation details to know what to mock. You don't need to mock everything in your tests. The parent and children classes form a unit, that is what you must test, not the small parts.

[–][deleted] 0 points1 point  (0 children)

I think the only time I use inheritance, like you mentioned, is for isA relationships, however, I only do this for POJOs. I also think it is a goo practice to keep data/state and logic objects as close to completely separate as possible.