I l@ve RuBoard Previous Section Next Section

Exercise 5.4

A library supports the following categories of lending materials, each with its own check-out and check-in policy. Organize these into an inheritance hierarchy:



book         audio book 


record       children's puppet 


video        Sega video game 


rental book  Sony Playstation video game 


CD-ROM book  Nintendo video game 

An inheritance hierarchy moves from the most abstract to the most specific. In this example, we are given concrete instances of materials loaned by a library. Our task is twofold. First, we must group common abstractions: the four book abstractions and the three video game abstractions. Second, we must provide additional classes that can serve as an abstract interface for the concrete instances. This must be done at two levels: at the level of each family of concrete classes, such as our books, and at the level of the entire library lending hierarchy.

For example, Sega, Sony Playstation, and Nintendo video games are specific instances of video games. To tie them together, I've introduced an abstract video game class. I've designated the book class as a concrete base class with the three other kinds of books as specialized instances. Finally, we need a root base class of our library lending materials.

In the following hierarchy, each tab represents an inheritance relationship. For example, audio, rental, and CD-ROM are inherited from book, which in turn is inherited from the abstract library_lending_material.



library_lending_material 


   book 


      audio book 


      rental book 


      CD-ROM book 


   children's puppet 


   record 


   video 


   video game 


      Sega 


      Sony Playstation 


      Nintendo 
    I l@ve RuBoard Previous Section Next Section