Ch7 Implementation
Ch7 Implementation
Control
1 system 1
1 1..n
Weather 1 1..n Weather
information station
system
1 1..n
Satellite 1
1
Report
weather
Report status
Weather
information
system
Restart
Shutdown
Reconfigure
Control
system Powersave
Remote
control
30/10/2014 Chapter 7 Design and Implementation 11
Use case description—Report weather
Communication link
Data collection
Transmitter Receiver
WeatherData
identifier airTemperatures
groundTemperatures
reportWeather ( )
windSpeeds
reportStatus ( )
windDirections
powerSave (instruments)
pressures
remoteControl (commands)
rainfall
reconfigure (commands)
restart (instruments) collect ( )
shutdown (instruments) summarize ( )
request (report)
acknowledge
reportWeather ()
send (report)
acknowledge
reply (report)
acknowledge
Controlled
Operation
shutdown() remoteControl()
reportStatus()
restart() Testing
Shutdown Running
«interface»
«interface» Remote Control
Reporting
startInstrument(instrument): iStatus
weatherReport (WS-Ident): Wreport stopInstrument (instrument): iStatus
statusReport (WS-Ident): Sreport collectData (instrument): iStatus
provideData (instrument ): string
² Name
§ A meaningful pattern identifier.
² Problem description.
² Solution description.
§ Not a concrete design but a template for a design solution that
can be instantiated in different ways.
² Consequences
§ The results and trade-offs of applying the pattern.
² Name
§ Observer.
² Description
§ Separates the display of object state from the object itself.
² Problem description
§ Used when multiple displays of state are needed.
² Solution description
§ See slide with UML description.
² Consequences
§ Optimisations to enhance display performance are impractical.
Pattern Observer
name
Description Separates the display of the state of an object from the object itself and
allows alternative displays to be provided. When the object state
changes, all displays are automatically notified and updated to reflect the
change.
Problem In many situations, you have to provide multiple displays of state
description information, such as a graphical display and a tabular display. Not all of
these may be known when the information is specified. All alternative
presentations should support interaction and, when the state is changed,
all displays must be updated.
This pattern may be used in all situations where more than one
display format for state information is required and where it is not
necessary for the object that maintains the state information to know
about the specific display formats used.
Solution This involves two abstract objects, Subject and Observer, and two concrete
description objects, ConcreteSubject and ConcreteObject, which inherit the attributes of the
related abstract objects. The abstract objects include general operations that are
applicable in all situations. The state to be displayed is maintained in
ConcreteSubject, which inherits operations from Subject allowing it to add and
remove Observers (each observer corresponds to a display) and to issue a
notification when the state has changed.
Consequences The subject only knows the abstract Observer and does not know details of the
concrete class. Therefore there is minimal coupling between these objects.
Because of this lack of knowledge, optimizations that enhance display
performance are impractical. Changes to the subject may cause a set of linked
updates to observers to be generated, some of which may not be necessary.
50
D
A
25
C
A B C D
B 0
Subject
Observer 1 A: 40 Observer 2
B: 25
C: 15
D: 20
ubject Observer
Observer) Update ()
(Observer)
for all o in observers
) o -> Update ()
teSubject ConcreteObserver
State observerState
² Singleton
² Factory Method
² Observer
² Adapter
System
Application systems
(COTS)
Abstraction Component
Programming
language libraries
Object
Change
proposals
System
building
Change
management
Version Release
management management
Host Target
Development Execution
platform platform
Download
IDE software Libraries