• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 21. Packaging Data and Functions... > Designing Good Superclasses and Subc...

Designing Good Superclasses and Subclasses: “Is” Versus “Has”

Much of the skill of OOP is in designing hierarchies of superclasses and subclasses that elegantly model a problem domain. Creating such hierarchies is far from a precise science, and no two programmers attacking the same problem will come up with exactly the same solution. Nevertheless, there is one general rule that will seldom, if ever, be broken: A subclass should have an “is” relationship to its superclass.

The “Is” Relationship

Each and every member of a subclass should belong to its superclass. For instance, a bald eagle “is” an eagle. An eagle “is” a raptor. A raptor “is” a bird. You will never find a bald eagle that is not an eagle, or a raptor that is not a bird.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint