This content has been marked as final. Show 3 replies
You should be able to use composition and delegation rather than inheritance to solve your issue.
Instead of thinking that a Client is an Admin (inheritance), think that a Client has some AdminRights (composition).
So instead of doing something like this:
You would do this:
mathiii wrote:It sounds like you're using inheritance to simply re-use some code, rather than because it actually models the domain. That's often the cause of awkwardness.
I have a situation where I cannot think of a good design without multiple inheritance, which isn't allowed by Java :
The structure is shown on the image in the link below.
I have classes NioClient and IoClient which both may handle Sockets. Those classes are extending a Client class which is an abstract class containing the common code for the concrete classes.
In the same way I have NioClientAdmin and IoClientAdmin extending a ClientAdmin containing common code. Those Admin classes are adding extra functionnalities to the default classes. That's why all the Admin classes must extend the associated default classes.