Tying It All Together: An Example

 <  Day Day Up  >  

Let's work on a simple example that will tie the concepts of inheritance, interfaces, composition, associations, and aggregations together into a single, short system diagram.

Consider the example used in Chapter 8, with one addition: We will add an Owner class that will take the dog out for walks.

Recall that the Dog class inherits directly from the Mammal class. The solid arrow represents this relationship between the Dog class and the Mammal class in Figure 9.9. The Nameable class is an interface that Dog implements, which is represented by the dashed arrow from the Dog class to the Nameable interface.

Figure 9.9. A UML diagram for the Dog example.

graphics/09fig09.gif

In this chapter, we are mostly concerned with associations and aggregations. The relationship between the Dog class and the Head class is considered aggregation because the head is actually part of the dog. The cardinality on the line connecting the two class diagrams specifies that a dog can have only a single head.

The relationship between the Dog class and the Owner class is association. The owner is clearly not part of the dog, or vice versa, so we can safely eliminate aggregation. However, the dog does require a service from the owner ”the act of taking him on a walk. The cardinality on the line connecting the Dog and Owner classes specifies that a dog can have one or more owners (for example, a wife and husband can both be considered owners , with shared responsibility for walking the dog).

These relationships ”inheritance, interfaces, composition, associations, and aggregations ”represent the bulk of the design work you will encounter when designing OO systems.

 <  Day Day Up  >  


Object-Oriented Thought Process
Object-Oriented Thought Process, The (3rd Edition)
ISBN: 0672330164
EAN: 2147483647
Year: 2003
Pages: 164
Authors: Matt Weisfeld

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net