Lec13 - November 10, 2008 1 Aggregation, Inheritance, and...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: November 10, 2008 1 Aggregation, Inheritance, and Polymorphism Lecture 13 — November 10, 2008 CS1101Y : Programming Methodology November 10, 2008 CS1101Y -- Programming Methodology 2 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 November 10, 2008 CS1101Y -- Programming Methodology 3 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. November 10, 2008 CS1101Y -- Programming Methodology 4 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. November 10, 2008 CS1101Y -- Programming Methodology 5 Composition ¡ A partial composition hierarchy for the human body: November 10, 2008 CS1101Y -- Programming Methodology 6 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....
View Full Document

This note was uploaded on 03/19/2012 for the course SOC 1101 taught by Professor A.tan during the Fall '08 term at National University of Singapore.

Page1 / 70

Lec13 - November 10, 2008 1 Aggregation, Inheritance, and...

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

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