The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 (Not So) Stupid Questions 5: Inheritance Versus Interfaces
Subject:  Dont let the language define the problem!
Date:  2005-10-15 04:53:17
From:  siver


I read the question and thought that it was interesting that although I've designed and coded a number of programs I never really been stuck at whether to implement something as a subclass or an interface. I think the reason for that is I don't worry too much about reusability and hiding code (the technical aspects of coding) in my first few attempts at my model. I simply try to describe the problem domain as clearly as I can with whatever makes the most sense to me at the time, e.g. A Chevy is a Car, inheritance or a Car is Driveable an interface. I use whichever "sounds" more appropriate for the problem at hand. I don't think that one is more correct than the other. I don't burden my model with constraints that are unlikely or unnecessary for the problem at hand. My model covers only a particular slice of reality not the whole thing as a result the problem could probably be solved with either approach. What you gain in functionality and speed with one solution, you may lose in clarity and maintainability and vice versa. Although it might be quite the CS quandry to think about pros and cons of inheritance vs interfaces in the abstract I am an engineer and practically speaking most real problems tend to lend themselves to one or the other design quite intuitively. At least this has been my experience.

 Feed java.net RSS Feeds