Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Announcements Attendance sheet is going around – be sure you sign it! First part of.

Similar presentations


Presentation on theme: "Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Announcements Attendance sheet is going around – be sure you sign it! First part of."— Presentation transcript:

1 Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Announcements Attendance sheet is going around – be sure you sign it! First part of essay assignment (choosing a topic) is posted on the website. Check it out!

2 Fall 2007CSE 115/503 Introduction to Computer Science for Majors I2 Association relationship We’ve seen one implementation of “knows a”: public class Dog { private Collar _collar; public Dog(Collar collar) { _collar = collar; } Now we will see a more flexible implementation.

3 Fall 2007CSE 115/503 Introduction to Computer Science for Majors I3 Essence of association We use an association relationship when we want to model that one object can communicate with another object (as in the composition relationship) but –there isn’t any lifetime link between the two objects, or –the objects in the relationship can change over time (think of Clifford’s collar).

4 Fall 2007CSE 115/503 Introduction to Computer Science for Majors I4 Changing the known property We want to be able to set a new value for the property (e.g. give Clifford a new collar). How can we do that? Using a “mutator” or “setter” method.

5 Fall 2007CSE 115/503 Introduction to Computer Science for Majors I5 mutator method public class Dog{ private Collar _collar; public Dog(Collar collar){ _collar = collar; } public void setCollar(Collar collar){ _collar = collar; }

6 Fall 2007CSE 115/503 Introduction to Computer Science for Majors I6 Constructor/mutator similarity Note the similarity between the constructor and the mutator. With respect to the _collar variable, they are doing essentially the same thing: allowing the invoker to set the value of the instance variable. Difference is that constructor sets value when Dog object is created, mutator changes the value at some later point in time.


Download ppt "Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Announcements Attendance sheet is going around – be sure you sign it! First part of."

Similar presentations


Ads by Google