Download presentation
Presentation is loading. Please wait.
1
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 645-4739 alphonce@buffalo.edu 1
3
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
4 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); }
5
5 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Class definition is shown in green:
6
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
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
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
9 Dog – Tail example in Java public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } Constructor definition is shown in green:
10
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
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
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
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
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
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
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
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
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:
19
UML Unified Modeling Language (Class Diagrams)
20
UML Unified Modeling Language –express design without reference to an implementation language For example
21
Composition in UML
22
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
23
package cse115; public class Dog { public Dog() { } package cse115; public class Tail { public Tail() { }
24
package cse115; public class Dog { private Tail _tail; public Dog() { _tail = new Tail(); } package cse115; public class Tail { public Tail() { }
25
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.
26
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() { }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.