chapter12 - Chapter12AggregationandInheritance 1 2 1...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Chapter 12 - Aggregation and Inheritance Composition Aggregation UML Class Diagram for Composition and Aggregation Car Dealership Program Inheritance Overview Inheritance Example - People in a Department Store Inheritance Terminology UML Class Diagrams for Inheritance Hierarchies Benefits of Inheritance Inheritance For a Superclass's  private  Instance Variables Using  super  to Call Superclass Constructor Calling a Superclass's Method from Within a Subclass  Default Call to Superclass Constructor Method Overriding The  final  Access Modifier Aggregation , Composition, and Inheritance Compared Aggregation, Composition, and Inheritance Combined Card Game Program 1 2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Composition Prior to this chapter, all of our objects have been  relatively simple, so we've been able to describe each  object with just a single class. But for an object that's more complex, you should  consider breaking up the object into its constituent  parts and defining one class as the whole and other  classes as parts of the whole. When the whole class is  the exclusive owner of the parts classes, then that  class organization is called a  composition . 1
Background image of page 2
3 Composition The concept of composition is not new; that's what we do with  complex objects in the real world: Every living creature and most manufactured products are made up  of parts. Often, each part is a subsystem that is itself made up of its  own set of subparts. Together, the whole system forms a  composition hierarchy. Note the human body composition hierarchy on the next slide. Remember that with a composition relationship, a component  part is limited to just one owner at a time. For example, a heart  can be in only one body at a time. 1 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Composition 1 A partial composition hierarchy for the human body: 3 2
Background image of page 4
5 Aggregation In a composition hierarchy, the relationship between a containing  class and one of its part classes is known as a  has-a  relationship.  For example, each human body has a  brain and has a  heart. There's another has-a relationship, called  aggregation , which is a  weaker form of composition. With aggregation,  one class is the  whole and other classes are parts of the whole (as with  composition), but there is no additional constraint that requires  parts to be exclusively owned by the whole. An aggregation example where the parts are not exclusively 
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/22/2010 for the course COMPSCI CS201 taught by Professor Sorenson during the Spring '10 term at Wisconsin Milwaukee.

Page1 / 44

chapter12 - Chapter12AggregationandInheritance 1 2 1...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online