Composition Using instance variables that are references to other objects class

Composition using instance variables that are

This preview shows page 12 - 18 out of 18 pages.

Composition Using instance variables that are references to other objects. class Fruit { class Fruit { // Return int number of pieces of peel that // resulted from the peeling activity. public int peel() { System.out.println("Peeling is appealing."); return 1; } } class Apple { private Fruit fruit = new Fruit(); public int peel() { return fruit.peel(); } } //... } class Apple { private Fruit fruit = new Fruit(); //... } The composition relationship 12
Image of page 12
13
Image of page 13
Aggregation and Composition - Aggregation specifies a whole-part relationship between two objects. - Composition is a stronger form of aggregation where the whole and parts have coincident lifetimes, and it is very common for the whole to manage the lifecycle of its parts. Examples of aggregation and composition. 14
Image of page 14
Singletons 15
Image of page 15
16
Image of page 16
17
Image of page 17
18
Image of page 18

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture