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

Slides:



Advertisements
Similar presentations
PHP functions What are Functions? A function structure:
Advertisements

CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Summary of the lecture We discussed –variable scope –instance variable declarations –variable lifetime.
Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Association relationship We’ve seen one implementation of “knows a”: public class Dog.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Lecture #5 Agenda Cell phones off & name signs out Review Questions? UML class diagram introduction Our first class definition!
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Syntax & terminology review While the following slides are not exactly what we did on the board (object diagrams are not shown here) they cover most of.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE 115/503 Introduction to Computer Science for Majors I1 Example Dog fido = new Dog(new Collar()); Dog rover = new Dog(new Collar()); rover.setCollar(fido.getCollar());
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Now What? What if we want to talk to something that was created somewhere else? E.g.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Fall 2005CSE 115/503 Introduction to Computer Science I1 Reminder Check the course web site on a regular basis:
CS 106 Introduction to Computer Science I 11 / 20 / 2006 Instructor: Michael Eckmann.
Week 4 Recap CSE 115 Spring Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the.
Where do objects come from? Objects are instances of classes We instantiate classes: –e.g.new chapter1.Terrarium() –There are three parts to this expression:
CS 106 Introduction to Computer Science I 03 / 21 / 2008 Instructor: Michael Eckmann.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Lecture #4 Agenda Announcements Review Questions? Classes and objects UML class diagrams Creating.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Announcements Attendance sheet is going around – be sure you sign it! First part of.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Fall 2005CSE 115/503 Introduction to Computer Science I1 Association Also called “knows a”. A relationship of knowing (e.g. Dog-Collar as opposed to Dog-Tail)
Week 5 Recap CSE 115 Spring Composition Informally called “has a” Represented in UML with a diamond- headed arc In code: Declare an instance variable.
CSE 115 Week 3 January 28 – February 1, Monday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation.
CSE 115 Week 4 February 4 - 8, Monday Announcements Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Software installation fest Tuesday.
Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Announcements Attendance sheet is going around – be sure you sign it! First part of.
Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 End of Week Five! Questions? First part of essay assignment (choosing a topic) is posted.
Week 3 Recap CSE 115 – Fall Java Source Code File Made up of: Package declaration Class definition.
1 Chapter 3 and 6– Classes, Objects and Methods Object-Oriented Programming Concepts – Read it from Java TutorialJava Tutorial Definition: A class is a.
Dale Roberts Introduction to Java - Access Specifiers Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
ECE122 Feb. 22, Any question on Vehicle sample code?
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
AP Computer Science A – Healdsburg High School 1 Unit 9 - Why Use Classes - Anatomy of a Class.
CS 139 Objects Based on a lecture by Dr. Farzana Rahman Assistant Professor Department of Computer Science.
Java Programming, Second Edition Chapter Three Using Methods, Classes, and Objects.
Objects as a programming concept
Objects as a programming concept
Haidong Xue Summer 2011, at GSU
Objects as a programming concept
FIGURE 4-10 Function Return Statements
PHP Classes and Objects
Using local variable without initialization is an error.
Classes & Objects: Examples
CSE 1030: Implementing GUI Mark Shtern.
Static is one of the modifiers that determine variable and method characteristics. The static modifier associates a variable or method with its class.
Which best describes the relationship between classes and objects?
Instance Method – CSC142 Computer Science II
Presentation transcript:

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.

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.

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:

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:

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:

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:

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:

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:

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:

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:

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:

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:

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:

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:

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:

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:

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: