Aggregation.

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

Dynamic allocation and deallocation of memory: Chapter 4, Slide 1.
B-Trees and Red Black Trees. Binary Trees B Trees spread data all over – Fine for memory – Bad on disks.
UML Diagrams: The Static Model Class Diagrams. The Static Model Define the static structure of the logical model Represent classes, class hierarchies.
Abstract Classes & Object Slicing. Pure Virtual Functions Virtual Function : Child class may override, if working with pointer/reference, check to see.
Pointers & Objects & Aggregation Who's your daddy?
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
Container Classes. How do we do better? Tough to delete correctly: startLocation.
Abstract Classes & Object Slicing. Object Slicing.
2-1 © Prentice Hall, 2004 Chapter 2: Introduction to Object Orientation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
If Our Child Is Young, Can I Make My Spouse Pay Into A College Account?
Run-Time Environments Chapter 7
COMP 53 – Week Eight Linked Lists.
Object-Orientated Analysis, Design and Programming
UML Diagrams: Class Diagrams The Static Analysis Model
Main issues: • What do we want to build • How do we write this down
Class Diagrams.
Andy Wang Object Oriented Programming in C++ COP 3330
Implementing Subprograms
Run-Time Storage Organization
UML - Unified Modeling Language
B+ Tree.
Paolo Ferragina Dipartimento di Informatica, Università di Pisa
An Introduction to Inheritance
Red-Black Trees Bottom-Up Deletion.
PROGRAMME F10 FUNCTIONS.
OO models with relational databases
UML Class Diagram: class Rectangle
A short introduction to UML Eivind J. Nordby Karlstad University
UML UML Data Modeling.
CSC 253 Lecture 8.
Barb Ericson Georgia Institute of Technology May 2006
Mendel…….. The Father of Genetics
UML Diagrams: The Static Model Class Diagrams
Automatics, Copy Constructor, and Assignment Operator
Introduction to Classes
Heterogeneous aggregate datatypes
CSC 253 Lecture 8.
Basic C++ What’s a declaration? What’s a definition?
Automatics, Copy Constructor, and Assignment Operator
Child Actor Component Templates
Recursion Chapter 11.
Linked List Intro CSCE 121 J. Michael Moore.
System Structure and Process Model
Red-Black Trees Bottom-Up Deletion.
Household Composition
Software Construction Lecture 2
Chapter 2 Underpinnings of Requirements Analysis
Forests D. J. Foreman.
Red-Black Trees Bottom-Up Deletion.
CISC/CMPE320 - Prof. McLeod
Dynamic Memory Management
UNIT V Run Time Environments.
Essential Class Operations
Destructor CSCE 121 J. Michael Moore.
Chapter 10: Method Overriding and method Overloading
Object Oriented Programming Review
Destructor CSCE 121.
3.4 Review PBS.
Method Overriding and method Overloading
COP 3330 Object-oriented Programming in C++
Object Oriented System Design Class Diagrams
Linked List Intro CSCE 121.
Essential Class Operations
Object Slicing & Dynamic Casts
Dynamic Memory Management
Starter How many different animals can you think of?
Balanced search trees: trees.
CMSC 202 Constructors Version 9/10.
Presentation transcript:

Aggregation

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"

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?

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

Plain Old Explored Child has their own Person as parent

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

3 Children Versions Pointer Version father/mother pointers to Person

Plain Old Explored Child points to a shared parent

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

3 Child Versions References Version Can share with reference vars:

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

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

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

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

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

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

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

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

Self-Reference Self-Aggregation is perfectly fine:

Self-Reference Class: Objects: