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
Special Visitor Sean Haneberg Microsoft XBoxLive Former UB-CSE student
4
Announcements Exam 2 – about 2.5 weeks away –covers material up to & including 10/15 –review on Monday 10/18 –exam on Wednesday 10/20
5
Agenda association relationship –constructor form –accessor/mutator form –variation on a theme capture the domain
6
Revisiting Clifford –dog-tail is one relationship –dog-collar is another
7
Another relationship One collar for its life…? A dog has-a tail; the tail is a part of the dog. We need something different to model the relationship between a dog and a collar.
8
Association No necessary lifetime link Two implementations: –The first is very similar to composition, but differs in one crucial respect: where the target class is instantiated. –The second, which decouples lifetimes completely, is a bit more complex but also more flexible.
9
Revisiting Clifford Dog-Tail relationship is COMPOSITION –Dog takes responsibility for creating a Tail Dog-Collar relationship is ASSOCIATION –Dog takes NO responsibility for creating Collar
10
First implementation 3 changes to source class: 1.Declaration of instance variable 2.Assignment of existing instance to the instance variable 3.Parameter of constructor is of same type as instance variable 1 2 3
11
Dog – Collar example in Java public class Dog { private Collar _collar; public Dog(Collar collar) { _collar = collar; } 1 2 3
12
UML See Eclipse example
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.