Composition

Composition - Object Or ient ed Design Composition Composit...

Info iconThis preview shows pages 1–12. 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

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: Object Or ient ed Design Composition Composit ion • I n composit ion, one or mor e member (s) of a class ar e object s of anot her class t ype • Composit ion is a “has-a” r elat ion • Ar gument s t o t he const r uct or of a m ember -object ar e specified in t he h eading par t of t he definit ion of t he const r uct or 2 • Define t he class personType. The class personType st or es a per son’s fir st name and last name. • Suppose we want t o keep t r ack of addit ional infor mat ion for a per son, such as a per sonal I D (e.g., a Social Secur it y number ) and a dat e of bir t h. • Because ever y per son has a per sonal I D and a dat e of bir t h, we can define a new class, called personalInfo, in which one of t he member s is an object of t he t ype personType. • We can declar e addit ional member s t o st or e t he per sonal I D and dat e of bir t h for t he class personalInfo. • Fir st we define anot her class, dateType, t o st or e only a per son’s dat e of bir t h. • Then we const r uct t he class personalInfo f r om t he classes personType and dateType. Composit ion (cont inued) • M ember -object s of a class ar e const r uct ed – I n t he or der t hey ar e declar ed • Not in t he or der t hey ar e list ed in t he const r uct or ’s member init ializat ion list – Befor e t he enclosing class object s ar e const r uct ed 12 ...
View Full Document

Page1 / 12

Composition - Object Or ient ed Design Composition Composit...

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