{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

set07 - Composition Jan 2000 ENEL 409 Dr M Moussavi 1...

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

View Full Document Right Arrow Icon
Jan. 2000 - ENEL 409 Dr. M. Moussavi 1 Composition Composition
Background image of page 1

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

View Full Document Right Arrow Icon
Jan. 2000 - ENEL 409 Dr. M. Moussavi 2 Composition Composition Composition: represents a has-a relationship between two classes. In other word composition is implemented by making one class a member of the other class
Background image of page 2
Jan. 2000 - ENEL 409 Dr. M. Moussavi 3 Composition (Continued) Composition (Continued) Composition denotes a whole/part relationship, with the ability to navigate from whole (aggregate) to its parts (attributes). The composition may or may not denote physical containment. Example: The relationship between a shareholder and his shares is not physical containment. This type of relationship is normally known as aggregation.
Background image of page 3

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

View Full Document Right Arrow Icon
Jan. 2000 - ENEL 409 Dr. M. Moussavi 4 Composition-Example (Continued) Composition-Example (Continued) class B { private: int b; public: B(int); // constructor of B get(); // member function of B }; class A { B myb;
Background image of page 4
Jan. 2000 - ENEL 409 Dr. M. Moussavi 5 Composition (Continued) Composition (Continued) In the previous example, the constructor of class A is responsible to invoke the constructor of class B. If your class doesn't have a constructor an internal default constructor built automatically by compiler will be invoked
Background image of page 5

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

View Full Document Right Arrow Icon
Jan. 2000 - ENEL 409 Dr. M. Moussavi 6 Composition (Continued) Composition (Continued) The constructor of class A, in the previous example must use its member initialization list to invoke the constructor of class B: A::A (int x) : myb(x) { }
Background image of page 6
Jan. 2000 - ENEL 409 Dr. M. Moussavi 7 Derivation and Inheritance Derivation and Inheritance
Background image of page 7

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

View Full Document Right Arrow Icon
Jan. 2000 - ENEL 409 Dr. M. Moussavi 8 Class Hierarchy Class Hierarchy Classes are some times related by inheritance : A subclass inherits behavior and structure from its super-class. A subclass also augments or redefines the behavior and structure of its super-class. Also known as generalization/specialization hierarchy.
Background image of page 8
Jan. 2000 - ENEL 409 Dr. M. Moussavi 9 Class Hierarchy (continued) Class Hierarchy (continued) Single inheritance Where subclasses can have only one immediate super-class. E.g. mammal canine feline primate dog wolf fox lion tiger puma chimpanzee gorilla orangutan
Background image of page 9

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

View Full Document Right Arrow Icon
Dr. M. Moussavi 10 Inheritance Inheritance Inheritance is a relationship among classes where a subclass inherits the structure and behavior of its super-class. Defines the “is a” or generalization/specialization hierarchy. Structure:
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 33

set07 - Composition Jan 2000 ENEL 409 Dr M Moussavi 1...

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

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