1 / 16

CSE 1030: Aggregation and Composition

CSE 1030: Aggregation and Composition. Mark Shtern. Summary. Aggregation Constructors Accessor/Mutators Collections. Collections. Copy Contractor Alias this.setBooks ( library.books ) Shallow Copy this.setBooks (new ArrayList ( library.getBooks ())) Deep Copy

hodgins
Download Presentation

CSE 1030: Aggregation and Composition

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 1030: Aggregation and Composition Mark Shtern

  2. Summary • Aggregation • Constructors • Accessor/Mutators • Collections

  3. Collections • Copy Contractor • 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? 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

More Related