Jump to content
Larry Ullman's Book Forums

Recommended Posts

This question regards application design and does not have a source code component.

 

Is it common practice, or good practice, to use an abstract class and and multiple interfaces (small i) together in the same application? Consider the example of an abstract class automobile. This general class would enforce the "is a" constraints of all automobile types. Several different interface(s) would be defined and applied to the subclasses of automobile based on the type of automobile being defined.

 

Does this seem reasonable? Or does defining an abstract class and multiple interfaces seem like over-kill?

Link to comment
Share on other sites

It depends. If all you want to do with the automobile is to represent a specif model of a make, the answer would be no. If you create anything where an automobile can exist with differences (i.e a truck, suv, etc) then an abstract base class could absolutely make sense.

 

Some principle like SOLID can probably help your understanding a bit. As for your question about interfaces, this should clear up some of those questions you have. As an example, all automobiles can drive. Implementing the interface Drivable thus probably make sense. If a group of similar object share other such similarities, another interface is probably the way to go. Steerable or GearShift (excuse my clumsy examples) could therefor also be viable interfaces.

 

So... It depends on your needs. There are no overarching non-breakable rules in software engineering, only best practices and different models for your data and behaviors.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...