Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 645-4739 1.

Similar presentations


Presentation on theme: "CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 645-4739 1."— Presentation transcript:

1 CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 645-4739 alphonce@buffalo.edu 1

2 Association association relationship –constructor form –accessor/mutator form –variation on a theme capture the domain

3 Revisiting Clifford –dog-tail is one relationship –dog-collar is another

4 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.

5 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.

6 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

7 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

8 Dog – Collar example in Java public class Dog { private Collar _collar; public Dog(Collar collar) { _collar = collar; } 1 2 3

9 UML See Eclipse example


Download ppt "CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 645-4739 1."

Similar presentations


Ads by Google