07 - Ch7 Design and Implementation
07 - Ch7 Design and Implementation
07 - Ch7 Design and Implementation
ENGINEERING
CO3001
WEEK 8, 9
Adapted from https://iansommerville.com/software-engineering-book/slides/
TOPICS COVERED
Software design:
identify software components and their
relationships, based on a customer’s requirements.
Implementation:
realizing the design as a program.
In this example, the system about the weather station is a system of weather stations
as a weather information system, an onboard satellite system, and a control system.
The cardinality information on the link shows that there is one control system but
several weather stations, one satellite, and one general weather information system.
Sep 2019 CHAPTER 7. DESIGN AND IMPLEMENTATION 9
WEATHER STATION USE CASES
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.
Sep 2019 CHAPTER 7. DESIGN AND IMPLEMENTATION 32
THE OBSERVER PATTERN (1)
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
description concrete objects, ConcreteSubject and ConcreteObserver, 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.
The ConcreteObserver maintains a copy of the state of
ConcreteSubject and implements the Update() interface of Observer
that allows these copies to be kept in step. The ConcreteObserver
automatically displays the state and reflects changes whenever the
state is updated.
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
Sep 2019 CHAPTER 7. DESIGN AND IMPLEMENTATION 34
to be generated, some of which may not be necessary.
MULTIPLE DISPLAYS USING THE OBSERVER PATTERN
Can do business?
+ numCanisters: int
- numWafers: int Attribute: type
- size: float
+: visible
from without
+ display()
- getNumSlotsOpen() Operations
+ setStatus()
Responsibilities:
-- describes each Place for
comments
canister undergoing
fabrication
Invariant of withdraw():
availableFundsI = max( 0, balanceI )
Precondition*:
xI denotes an attribute;
withdrawalAmountP >= 0 AND xP denotes a function parameter;
balanceI - withdrawalAmountP x' is the value of x after execution;
X denotes a class constant
>= OVERDRAFT_MAX
Postcondition*:
balanceI' = balanceI - withdrawalAmountP
Use Captions
Balance
Symmetry
Group
Proportion
like elements