Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.

Similar presentations


Presentation on theme: "Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of."— Presentation transcript:

1 Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of part class/type in the whole class. –Instatiation of part class in whole class constructor. –Assignment of new part instance to instance variable.

2 Fall 2005CSE 115/503 Introduction to Computer Science I2 Important points about composition Whole has responsibility for creating its parts (which is why instantiation of parts happens in constructor of whole). Whole can communicate with parts. This is why an instance variable is declared: to establish a name for the newly created object.

3 Fall 2005CSE 115/503 Introduction to Computer Science I3 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Class definition is shown in green:

4 Fall 2005CSE 115/503 Introduction to Computer Science I4 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Instance variable name is shown in green:

5 Fall 2005CSE 115/503 Introduction to Computer Science I5 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Instance variable declaration is shown in green:

6 Fall 2005CSE 115/503 Introduction to Computer Science I6 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Access control modifiers are shown in green:

7 Fall 2005CSE 115/503 Introduction to Computer Science I7 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Constructor definition is shown in green:

8 Fall 2005CSE 115/503 Introduction to Computer Science I8 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Constructor definition is shown in green:

9 Fall 2005CSE 115/503 Introduction to Computer Science I9 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Header of constructor definition is shown in green:

10 Fall 2005CSE 115/503 Introduction to Computer Science I10 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Access control modifier in header of constructor definition is shown in green:

11 Fall 2005CSE 115/503 Introduction to Computer Science I11 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Name of constructor in header of constructor definition is shown in green:

12 Fall 2005CSE 115/503 Introduction to Computer Science I12 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Parameter list in header of constructor definition is shown in green:

13 Fall 2005CSE 115/503 Introduction to Computer Science I13 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Instantiation of class Dog is shown in green:

14 Fall 2005CSE 115/503 Introduction to Computer Science I14 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } ‘new’ operator in instantiation of class Dog is shown in green:

15 Fall 2005CSE 115/503 Introduction to Computer Science I15 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Use of constructor in instantiation of Dog class is shown in green:

16 Fall 2005CSE 115/503 Introduction to Computer Science I16 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Argument list in instantiation of class Dog is shown in green:

17 Fall 2005CSE 115/503 Introduction to Computer Science I17 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Dog(); } Assignment of new Dog instance to instance variable is shown in green:


Download ppt "Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of."

Similar presentations


Ads by Google