Links, objects, object diagrams Section 7.8.1 Download

Transcript
Class Diagrams
Object Instances
Links
Object diagram
Interfaces
Chapter 7: 7.2, 7.5.5, 7.8.1, 7.82
Sept 2005
92.3913
Ron McFadyen
1
Links, objects, object diagrams
Section 7.8.1
Goes through a sequence of diagrams illustrating how an
analysts works out the solution to a modeling problem
Analyst constructs object diagrams, then decides on the
proper class diagram.
Figures 7-27, 28, 29, 30
7-27 first draft – has a problem with the address objects
7-28 second draft – happens to use containment notation for
composition – analyst clarifies role of addresses in the solution
7-29 above revised, but now correctly drawn
7.30 class diagram that fits the final object diagram
Sept 2005
92.3913
Ron McFadyen
2
Links, objects, object diagrams
Section 7.8.1
Figure 7-30
CarSharer
startsAt
1
1
registers
*
1
Journey
Address
1
1
endsAt
-homeAddress
1
Sept 2005
92.3913
Ron McFadyen
3
Interfaces
Section 7.5.5
An interface is special type of class that cannot be instantiated.
An application can never instantiate an interface.
An interface defines a set of public attributes and operations that
some class must use (depends on)
There is no behaviour defined, no method coded
Some other class inherits the interface and provides the
implementation
Sept 2005
92.3913
Ron McFadyen
4
From Head First …
package headfirst.observer.weatherobservable;
import java.util.Observable;
import java.util.Observer;
public class ForecastDisplay implements Observer,
…
public void update(Observable observable, Object arg) {
if (observable instanceof WeatherData) {
WeatherData weatherData = (WeatherData)observable;
lastPressure = currentPressure;
currentPressure = weatherData.getPressure();
display();
}
}
public void display() {
System.out.print("Forecast: ");
if (currentPressure > lastPressure) {
System.out.println("Improving weather on the way!");
}…
Sept 2005
92.3913
Ron McFadyen
5
From Head First …
package headfirst.observer.weatherobservable;
import java.util.Observable;
import java.util.Observer;
public class StatisticsDisplay implements Observer, DisplayElement {
private float maxTemp = 0.0f;
…
public void update(Observable observable, Object arg) {
if (observable instanceof WeatherData) {
WeatherData weatherData = (WeatherData)observable;
float temp = weatherData.getTemperature();
…
display();
}
}
public void display() {
System.out.println("Avg/Max/Min temperature = " …
Sept 2005
92.3913
Ron McFadyen
6
From Head First …
<<interface>>
Observer
update()
These classes implement the
update operation
StatisticsDisplay
Sept 2005
ForecastDisplay
92.3913
Ron McFadyen
7
Similar