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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...