Chapter-2-Design and ImplementationModule 2
Chapter-2-Design and ImplementationModule 2
(21CSE151)
Module 2
Chapter-2
Design and Implementation
By,
Dr. Chaitra M
Topics covered
Name
A meaningful (reference to the pattern) pattern identifier.
Problem description.
explains when the pattern may be applied.
Solution description.
Not a concrete design but a template for a design solution that can be
instantiated in different ways. This is expressed graphically and shows the
relationships between the objects and object classes in the solution.
Consequences
This can help designers understand whether or not a pattern can be used
in a particular situation.
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
(design solution) 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 objects,
description 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.
To use patterns in your design, you need to recognize that any design
problem you are facing may have an associated pattern that can be applied.
Tell several objects that the state of some other object has changed
(Observer pattern).
By reusing existing software, you can develop new systems more quickly, with fewer
development risks and also lower costs.
The costs of the time spent in looking for software to reuse
and assessing whether or not it meets your needs.
Where applicable, the costs of buying the reusable software.
For large off-the-shelf systems, these costs can be very
high.
The costs of adapting and configuring the reusable software
components or systems to reflect the requirements of the
system that you are developing.
The costs of integrating reusable software elements with
each other (if you are using software from different sources)
and with the new code that you have developed.
Chapter 2 Design and Implementation 49
Configuration management