CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Special Visitor Sean Haneberg Microsoft XBoxLive Former UB-CSE student
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
Agenda association relationship –constructor form –accessor/mutator form –variation on a theme capture the domain
Revisiting Clifford –dog-tail is one relationship –dog-collar is another
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.
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.
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
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
Dog – Collar example in Java public class Dog { private Collar _collar; public Dog(Collar collar) { _collar = collar; } 1 2 3
UML See Eclipse example