Download - Lec 33 - inheritance
![Page 1: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/1.jpg)
InheritanceInheritance
Chapter: Chapter: 0909
Lecture: 33Lecture: 33
Date: 10.10.2012Date: 10.10.2012
![Page 2: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/2.jpg)
Class HierarchiesClass Hierarchies
![Page 3: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/3.jpg)
Public and Private Public and Private InheritanceInheritance
class employeeclass employee //base class//base class
{{ };};
class teacher : class teacher : publicpublic employee employee //publicly-//publicly-derivedderived
{{ };};
class teacher : class teacher : privateprivate employee employee//privately-derived//privately-derived
{{ };};
![Page 4: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/4.jpg)
Public and Private Public and Private InheritanceInheritance
![Page 5: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/5.jpg)
Levels of InheritanceLevels of Inheritance Classes can be derived from classes that Classes can be derived from classes that
are themselves derived.are themselves derived.
![Page 6: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/6.jpg)
Levels of HierarchiesLevels of Hierarchies
![Page 7: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/7.jpg)
Multiple InheritanceMultiple Inheritance
A class can be derived from more than one A class can be derived from more than one base classbase class
![Page 8: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/8.jpg)
Multiple InheritanceMultiple Inheritance
![Page 9: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/9.jpg)
Aggregation: Aggregation: Classes Within Classes Within ClassesClasses
Both inheritance and aggregation are class Both inheritance and aggregation are class relationships.relationships.
Inheritance is Inheritance is “kind of” “kind of” relationship - relationship - association.association.
Aggregation is Aggregation is “has a” “has a” relationship - associationrelationship - association Def. Def. AggregationAggregation - Several things grouped - Several things grouped
together together
or considered as a whole.or considered as a whole.
![Page 10: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/10.jpg)
Aggregation: Aggregation: Classes Within Classes Within ClassesClasses
Both inheritance and aggregation are class Both inheritance and aggregation are class relationships.relationships.
Inheritance is Inheritance is “kind of” “kind of” relationship - relationship - association.association.
Aggregation is Aggregation is “has a” “has a” relationship - associationrelationship - association Def. Def. AggregationAggregation - Several things grouped - Several things grouped
together together
or considered as a whole.or considered as a whole.
![Page 11: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/11.jpg)
Aggregation: Aggregation: Classes Within Classes Within ClassesClasses
Aggregation may occur when one object is an attribute Aggregation may occur when one object is an attribute of another. In other words, one class contains objects of another. In other words, one class contains objects of another class.of another class.
Example:Example:
class Aclass A
{{ };};
class Bclass B
{{
A objA; A objA; //object of class A is an attribute //object of class A is an attribute of class Bof class B
};};
![Page 12: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/12.jpg)
Aggregation: Aggregation: Classes Within Classes Within ClassesClasses
![Page 13: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/13.jpg)
Aggregation: Aggregation: Classes Within Classes Within ClassesClasses
![Page 14: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/14.jpg)
Composition: Composition: A Stronger A Stronger AggregationAggregation
Composition is a stronger form of aggregation, Composition is a stronger form of aggregation, having all its plus two morehaving all its plus two more The part may belong to only one wholeThe part may belong to only one whole The lifetime of the part is the same as the lifetime of The lifetime of the part is the same as the lifetime of thethe
wholewhole While aggregation is a While aggregation is a “has a” “has a” relationship, relationship,
composition is a composition is a “consists of” “consists of” relationship. relationship.
![Page 15: Lec 33 - inheritance](https://reader031.vdocuments.net/reader031/viewer/2022013011/555e33f3d8b42aad058b462b/html5/thumbnails/15.jpg)
Composition: Composition: A Stronger A Stronger AggregationAggregation
Composition is a stronger form of aggregation, Composition is a stronger form of aggregation, having all its plus two morehaving all its plus two more The part may belong to only one wholeThe part may belong to only one whole The lifetime of the part is the same as the lifetime of The lifetime of the part is the same as the lifetime of thethe
wholewhole While aggregation is a While aggregation is a “has a” “has a” relationship, relationship,
composition is a composition is a “consists of” “consists of” relationship. relationship.