Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 1030: Aggregation and Composition

Similar presentations


Presentation on theme: "CSE 1030: Aggregation and Composition"— Presentation transcript:

1 CSE 1030: Aggregation and Composition
Mark Shtern

2 Summary Aggregation Constructors Accessor/Mutators Collections

3 Collections Copy Contractor ArrayList copy= new ArrayList();
Alias this.setBooks(library.books) Shallow Copy this.setBooks(new ArrayList(library.getBooks())) Deep Copy ArrayList copy= new ArrayList(); for (Book book:books) copy.add(new Book(book)); this.setBooks(copy);

4 What is Composition Object Composition is a way to combine simple object into more complex ones Composite objects are usually expressed by means of references from one object to another Exactly like Aggregation except that the lifetime of the 'part' is controlled by the 'whole'

5 Is it composition? Carburetor carburetor = new Carburetor(); car = new Car(carburetor); Answer: NO

6 Is it composition? Carburetor carburetor = new Carburetor(); car = new Car(carburetor); Answer: Yes

7 Is it possible? Answer: NO
Carburetor carburetor = new Carburetor(); car = new Car(carburetor); Carburetor carburetor1 = carburetor; carburetor = car.getCarburetor(); Answer: NO

8 Is composition correctly implemented?
Carburetor carburetor = new Carburetor(); car = new Car(carburetor); carburetor = car.getCarburetor(); Answer: When carburetor is immutable object then yes, otherwise no

9 Is composition correctly implemented?
Carburetor carburetor = new Carburetor(); car = new Car(carburetor); carburetor = car.getCarburetor(); Answer: Yes

10 UML Diagram public Car { private Carburetor carburetor; Car () {
carburetor = new Carburetor(); }

11 Constructor Carburetor carburetor = new Carburetor(); car = new Car(carburetor); public Car(Carburetor carburetor) { this.setCarburator(carburetor); }

12 Method section Accessor public Carburetor getCarburetor() {
return new Carburetor (this.carburator); }

13 Method section Mutator public boolean setCarburetor(Carburetor c) {
// validation section // returns false if input is invalid this.carburator = new Carburetor(c); return true; }

14 Implementing Inheritance

15 Ex601 Develop an directory application which stores personal information about students, faculty and staff. In addition to the information commonly found in telephone books, your directory contains the following data Student  Major Staff and Faculty  Room Faculty Office hours Staff Title

16 Design


Download ppt "CSE 1030: Aggregation and Composition"

Similar presentations


Ads by Google