CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Agenda Exam reminder –First exam on Wednesday, Sept 28 –Monday Sept 26 is review day (come with questions) –No scheduled recitations next week Last time: –Relationships in model and code first relationship: composition –Lifetime/Scope process memory Today –Brief review –Unified Modeling Language (UML) class diagrams
4 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); }
5 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Class definition is shown in green:
6 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Instance variable name is shown in green:
7 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Instance variable declaration is shown in green:
8 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Access control modifiers are shown in green: Note that access control modifier of _tail is private, not public.
9 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Constructor definition is shown in green:
10 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Header of constructor definition is shown in green:
11 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Access control modifier in header of constructor definition is shown in green:
12 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Name of constructor in header of constructor definition is shown in green:
13 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Parameter list in header of constructor definition is shown in green:
14 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Instantiation of class Tail is shown in green:
15 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } ‘new’ operator in instantiation of class Tail is shown in green:
16 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Use of constructor in instantiation of Tail class is shown in green:
17 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Argument list in instantiation of class Tail is shown in green:
18 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Assignment of new Tail instance to instance variable is shown in green:
UML Unified Modeling Language (Class Diagrams)
UML Unified Modeling Language –express design without reference to an implementation language For example
Composition in UML
Binary Class Relationships: directional binary two classes are involved – source class has code modification – target class does not composition –source: WHOLE –target: PART in diagram: –line decoration is on source/WHOLE –show only detail that’s needed/desired
package cse115; public class Dog { public Dog() { } package cse115; public class Tail { public Tail() { }
package cse115; public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } package cse115; public class Tail { public Tail() { }
Questions (from lecture last year) Can you define more than one instance variable in a class definition? Can Dog have a composition relationship with other classes too? ANSWER: Yes! See example on next slide (which shows Dog – Nose composition). Also talked about Dog-Paw composition of cardinality 4.
package cse115; public class Dog { private Tail _tail; private Nose _nose; public Dog() { _tail = new Tail(); _nose = new Nose(); } package cse115; public class Tail { public Tail() { }