Presentation is loading. Please wait.

Presentation is loading. Please wait.

Aggregation.

Similar presentations


Presentation on theme: "Aggregation."— Presentation transcript:

1 Aggregation

2 Pointer Uses Objects need pointers for: Dynamic Memory Sharing Objects
Need to create data on heap and have pointers to it Sharing Objects Want two things to know about same "Bob"

3 A riddle… Bob, Candace, Ernie and Sue are People
Ernie and Sue are Childs Both are children of Bob and Candace How many people are there named Bob?

4 3 Child Versions Plain Old Variable Version
Father/mother are Person objects

5 Plain Old Explored Child has their own Person as parent

6 3 Child Versions Plain Old Variable Version
Father/mother are objects that exist within Child Each Child has own copies of father/mother

7 3 Children Versions Pointer Version father/mother pointers to Person

8 Plain Old Explored Child points to a shared parent

9 3 Children Versions Pointer Version
Father/mother are pointers to external objects Parent's shared… probably not owned

10 3 Child Versions References Version Can share with reference vars:

11 3 Children Versions ReferenceVersion Fussy
No way to change parent later Definitely not owned

12 Ownership General rules of thumb: Plain Variable Owns memory it labels

13 Ownership General rules of thumb: Plain Variable Owns memory it labels
Reference Variable Does not own memory of thing it references

14 Ownership General rules of thumb: Plain Variable Owns memory it labels
Reference Variable Does not own memory of thing it references Pointer May or may not own memory Only one pointer can

15 UML Aggregation vs Compostion
Composition : has-a built using other object, object only exists as part of this one C++ standard variable

16 UML Aggregation vs Compostion
Aggregation : has-a built using other object, but not necessarily owned C++ pointer/reference

17 Class vs Object Diagrams
Class Diagram: Object Diagram: 1 box per class box per object

18 Self-Reference C++ does not allow self-composition

19 Self-Reference Self-Aggregation is perfectly fine:

20 Self-Reference Class: Objects:


Download ppt "Aggregation."

Similar presentations


Ads by Google