6-Composition

6-Composition - in which one of the members is an object of...

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

View Full Document Right Arrow Icon
Object Oriented Design Composition
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 In composition, one or more member(s) of a class are objects of another class type Composition is a “has-a” relation Arguments to the constructor of a member-object are specified in the heading part of the definition of the constructor
Background image of page 2
Define the class personType . The class personType stores a person’s first name and last name. Suppose we want to keep track of additional information for a person, such as a personal ID (e.g., a Social Security number) and a date of birth. Because every person has a personal ID and a date of birth, we can define a new class , called personalInfo
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

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

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

Unformatted text preview: , in which one of the members is an object of the type personType . • We can declare additional members to store the personal ID and date of birth for the class personalInfo . • First we define another class , dateType , to store only a person’s date of birth. • Then we construct the class personalInfo from the class es personType and dateType . 12 Composition (continued) • Member-objects of a class are constructed – In the order they are declared • Not in the order they are listed in the constructor’s member initialization list – Before the enclosing class objects are constructed...
View Full Document

This note was uploaded on 05/03/2009 for the course CSCI 101L taught by Professor Ghyam during the Spring '07 term at USC.

Page1 / 12

6-Composition - in which one of the members is an object of...

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

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