SECh1214

83
Slide 1 Architectural design process System structuring Repository model Client-Server model Abstract machine (layered) model Control modelling Centralised control • Call-return model • Manager model Event-based control Broadcast model • Interrupt-driven model Modular decomposition Object model Data-Flow model

description

 

Transcript of SECh1214

Page 1: SECh1214

Slide 1

3 minute review of last week -- Architectural design process

System structuring• Repository model• Client-Server model• Abstract machine (layered) model

Control modelling• Centralised control

• Call-return model• Manager model

• Event-based control• Broadcast model• Interrupt-driven model

Modular decomposition • Object model• Data-Flow model

Page 2: SECh1214

Slide 2

13 minute review of last week -- Formal SpecificationsSymbol_Table New --> Table Enter (Table, Symbol, Type) --> Table Lookup (Table, Symbol) --> Type Delete (Table, Symbol) --> Table Replace (Table, Symbol, Type) --> Table

Lookup(New, S) = UndefinedLookup(Enter(ST, S1, T1), S2) = if S1=S2 then T1

else Lookup(ST, S2)

Delete(New,S2) = undefinedDelete(Enter(ST, S1,T1), S2) = if S1=S2 then ST

else Enter(Delete(ST, S2), S1, T1)

Replace(Replace(

Page 3: SECh1214

Slide 3

Ch. 12 - Object-oriented Design Designing systems using self-contained objects

and object classes Advantages of OOD

• Easier maintenance. Objects may be understood as stand-alone entities

• Objects are appropriate reusable components Characteristics of OOD

• Shared data areas are eliminated. Objects communicate by message passing

• Objects may be distributed and may execute sequentially or in parallel

Page 4: SECh1214

Slide 4

Object-oriented development Object-oriented analysis, design and programming

are related but distinct OOA is concerned with developing an object

model of the application domain OOD is concerned with developing an object-

oriented system model to implement requirements OOP is concerned with realising an OOD using an

OO programming language such as Java or C++

Page 5: SECh1214

Slide 5

12.1 Objects and object classes Objects are entities in a

software system which represent instances of real-world and system entities

Object classes are templates for objects. They may be used to create objects

Object classes may inherit attributes and services from other object classes

Employee

name: stringaddress: stringdateOfBirth: DateemployeeNo: integersocialSecurityNo: stringdepartment: Deptmanager: Employeesalary: integerstatus: {current, left, retired}taxCode: integer. . .

join ()leave ()retire ()changeDetails ()

Page 6: SECh1214

Slide 6

Object communication Conceptually, objects communicate by message

passing. Messages

• The name of the service requested by the calling object.

• Copies of the information required to execute the service and the name of a holder for the result of the service.

In practice, messages are often implemented by procedure calls• v = circularBuffer.Get () ; • thermostat.setTemp (20) ;

Page 7: SECh1214

Slide 7

Generalisation and inheritance Objects are members of classes which define

attribute types and operations Classes may be arranged in a class hierarchy

where one class (a super-class) is a generalisation of one or more other classes (sub-classes)

A sub-class inherits the attributes and operations from its super class and may add new methods or attributes of its own

Generalisation in the UML is implemented as inheritance in OO programming languages

Page 8: SECh1214

Slide 8

A generalisation hierarchyEmployee

Programmer

projectprogLanguage

Manager

ProjectManager

budgetsControlled

dateAppointed

projects

Dept.Manager

StrategicManager

dept responsibilities

Page 9: SECh1214

Slide 9

Advantages of inheritance It is an abstraction mechanism which may be used

to classify entities It is a reuse mechanism at both the design and the

programming level The inheritance graph is a source of organisational

knowledge about domains and systems

Page 10: SECh1214

Slide 10

Problems with inheritance Object classes are not self-contained. they cannot

be understood without reference to their super-classes

Designers have a tendency to reuse the inheritance graph created during analysis. Can lead to significant inefficiency

The inheritance graphs of analysis, design and implementation have different functions and should be separately maintained

Page 11: SECh1214

Slide 11

Inheritance and OOD There are differing views as to whether

inheritance is fundamental to OOD.• View 1. Identifying the inheritance hierarchy or

network is a fundamental part of object-oriented design. Obviously this can only be implemented using an OOPL.

• View 2. Inheritance is a useful implementation concept which allows reuse of attribute and operation definitions. Identifying an inheritance hierarchy at the design stage places unnecessary restrictions on the implementation

Page 12: SECh1214

Slide 12

Concurrent objects The nature of objects as self-contained entities

make them suitable for concurrent implementation The message-passing model of object

communication can be implemented directly if objects are running on separate processors in a distributed system

In Java, threads are used for implementing concurrency

Threads must include a method called run() and this is started up by the Java run-time system

Page 13: SECh1214

Slide 13

Servers and active objects Servers.

• The object is implemented as a parallel process (server) with entry points corresponding to object operations. If no calls are made to it, the object suspends itself and waits for further requests for service

Active objects• Objects are implemented as parallel processes and the

internal object state may be changed by the object itself and not simply by external calls

Page 14: SECh1214

Slide 14

Active transponder object Active objects may have their attributes modified

by external operations but may also update them autonomously using internal operations

Transponder object broadcasts an aircraft’s position. The position may be updated using a satellite navigation system.

Page 15: SECh1214

Slide 15

An active transponder objectclass Transponder extends Thread {

Position currentPosition ;Coords c1, c2 ;Satellite sat1, sat2 ;Navigator theNavigator ;

public Position givePosition () { return currentPosition; }

public void run () { while (true) { c1 = sat1.position () ;

c2 = sat2.position () ;currentPosition = theNavigator.compute (c1, c2) ;

} }

} //Transponder

Page 16: SECh1214

Slide 16

12.2 An object-oriented design process

Define the context and modes of use of the system Design the system architecture Identify the principal system objects Develop design models Specify object interfaces

Page 17: SECh1214

Slide 17

Weather system description

A weather data collection system is required to generate weather maps on a regular basis using data collected from remote, unattended weather stations and other data sources such as weather observers, balloons and satellites. Weather stations transmit their data to the area computer in response to a request from that machine.

The area computer validates the collected data and integrates it with the data from different sources. The integrated data is archived and, using data from this archive and a digitised map database a set of local weather maps is created. Maps may be printed for distribution on a special-purpose map printer or may be displayed in a number of different formats.

Page 18: SECh1214

Slide 18

Layered architecture

«subsystem»Data collection

«subsystem»Data processing

«subsystem»Data archiving

«subsystem»Data display

Data collection layer where objectsare concerned with acquiring datafrom remote sources

Data processing layer where objectsare concerned with checking andintegrating the collected data

Data archiving layer where objectsare concerned with storing the data for future processing

Data display layer where objects areconcerned with preparing andpresenting the data in a human-readable form

Page 19: SECh1214

Slide 19

Weather station description

A weather station is a package of software controlled instruments which collects data, performs some data processing and transmits this data for further processing. The instruments include air and ground thermometers, an anemometer, a wind vane, a barometer and a rain gauge. Data is collected every five minutes.

When a command is issued to transmit the weather data, the weather station processes and summarises the collected data. The summarised data is transmitted to the mapping computer when a request is received.

Page 20: SECh1214

Slide 20

System context and models of use

Develop an understanding of the relationships between the software being designed and its external environment

System context• A static model that describes other systems in the

environment. Use a subsystem model to show other systems. Following slide shows the systems around the weather station system.

Model of system use• A dynamic model that describes how the system interacts

with its environment. Use use-cases to show interactions

Page 21: SECh1214

Slide 21

Subsystems in the weather mapping system

«subsystem»Data collection

«subsystem»Data processing

«subsystem»Data archiving

«subsystem»Data display

Weatherstation

Satellite

Comms

Balloon

Observer

Datachecking

Dataintegration

Map store Data store

Datastorage

Map

Userinterface

Mapdisplay

Mapprinter

Page 22: SECh1214

Slide 22

Use-cases for the weather station

Startup

Shutdown

Report

Calibrate

Test

Page 23: SECh1214

Slide 23

Use-case description

System Weather station

Use-case Report

Actors Weather data collection system, Weather station

Data The weather station sends a summary of the weather data that has beencollected from the instruments in the collection period to the weather datacollection system. The data sent are the maximum minimum and averageground and air temperatures, the maximum, minimum and average airpressures, the maximum, minimum and average wind speeds, the totalrainfall and the wind direction as sampled at 5 minute intervals.

Stimulus The weather data collection system establishes a modem link with the weatherstation and requests transmission of the data.

Response The summarised data is sent to the weather data collection system

Comments Weather stations are usually asked to report once per hour but this frequencymay differ from one station to the other and may be modified in future.

Page 24: SECh1214

Slide 24

Architectural design

Once interactions between the system and its environment have been understood, you use this information for designing the system architecture

Layered architecture is appropriate for the weather station• Interface layer for handling communications

• Data collection layer for managing instruments

• Instruments layer for collecting data

Page 25: SECh1214

Slide 25

Weather station architecture

«subsystem»Data collection

«subsystem»Instruments

«subsystem»Interface

Weather station

Manages allexternal

communications

Collects andsummarisesweather data

Package ofinstruments for raw

data collections

Page 26: SECh1214

Slide 26

Object identification Identifying objects (or object classes) is the most

difficult part of object oriented design There is no 'magic formula' for object

identification. It relies on the skill, experience and domain knowledge of system designers

Object identification is an iterative process. You are unlikely to get it right first time

Page 27: SECh1214

Slide 27

Approaches to identification Use a grammatical approach based on a natural

language description of the system Base the identification on tangible things in the

application domain Use a behavioural approach and identify objects

based on what participates in what behaviour Use a scenario-based analysis. The objects,

attributes and methods in each scenario are identified

Page 28: SECh1214

Slide 28

Weather station object classes

Ground thermometer, Anemometer, Barometer• Application domain objects that are ‘hardware’

objects related to the instruments in the system Weather station

• The basic interface of the weather station to its environment. It therefore reflects the interactions identified in the use-case model

Weather data• Encapsulates the summarised data from the

instruments

Page 29: SECh1214

Slide 29

Weather station object classes

identifier

reportWeather ()calibrate (instruments)test ()startup (instruments)shutdown (instruments)

WeatherStation

test ()calibrate ()

Groundthermometer

temperature

Anemometer

windSpeedwindDirection

test ()

Barometer

pressureheight

test ()calibrate ()

WeatherData

airTemperaturesgroundTemperatureswindSpeedswindDirectionspressuresrainfall

collect ()summarise ()

Page 30: SECh1214

Slide 30

Further objects and object refinement

Use domain knowledge to identify more objects and operations• Weather stations should have a unique identifier

• Weather stations are remotely situated so instrument failures have to be reported automatically. Therefore attributes and operations for self-checking are required

Active or passive objects• In this case, objects are passive and collect data on

request rather than autonomously. This introduces flexibility at the expense of controller processing time

Page 31: SECh1214

Slide 31

Design models

Design models show the objects and object classes and relationships between these entities

Static models describe the static structure of the system in terms of object classes and relationships• Sub-system models that show logical groupings of objects

into coherent subsystems Dynamic models describe the dynamic interactions

between objects.• Sequence models show the sequence of object interactions

• State machine models show how individual objects change their state in response to events

Page 32: SECh1214

Slide 32

Subsystem models

Shows how the design is organised into logically related groups of objects

In the UML, these are shown using packages.

This is a logical model. The actual organisation of objects in the system may be different.

«subsystem»Interface

CommsController

WeatherStation

«subsystem»Data collection

«subsystem»Instruments

Air thermometer

WeatherData

Ground thermometer

Anemometer

WindVane

RainGauge

InstrumentStatus

Barometer

Page 33: SECh1214

Slide 33

Sequence models

Sequence models show the sequence of object interactions that take place• Objects are arranged horizontally across the top

• Time is represented vertically so models are read top to bottom

• Interactions are represented by labelled arrows, Different styles of arrow represent different types of interaction

• A thin rectangle in an object lifeline represents the time when the object is the controlling object in the system

Page 34: SECh1214

Slide 34

Data collection sequence:CommsController

request (report)

acknowledge ()report ()

summarise ()

reply (report)

acknowledge ()

send (report)

:WeatherStation :WeatherData

Page 35: SECh1214

Slide 35

Statecharts

Show how objects respond to different service requests and the state transitions triggered by these requests• If object state is Shutdown then it responds to a Startup()

message

• In the waiting state the object is waiting for further messages

• If reportWeather () then system moves to summarising state

• If calibrate () the system moves to a calibrating state

• A collecting state is entered when a clock signal is received

Page 36: SECh1214

Slide 36

Weather station state diagram

Shutdown Waiting Testing

Transmitting

Collecting

Summarising

Calibrating

transmission done

calibrate ()

test ()startup ()

shutdown ()

calibration OK

test complete

weather summarycomplete

clock collectiondone

Operation

reportWeather ()

Page 37: SECh1214

Slide 37

Object interface specification

Object interfaces have to be specified so that the objects and other components can be designed in parallel

Designers should avoid designing the interface representation but should hide this in the object itself

Objects may have several interfaces which are viewpoints on the methods provided

The UML uses class diagrams for interface specification but Java may also be used

Page 38: SECh1214

Slide 38

Weather station interfaceinterface WeatherStation {

public void WeatherStation () ;

public void startup () ;public void startup (Instrument i) ;

public void shutdown () ;public void shutdown (Instrument i) ;

public void reportWeather ( ) ;

public void test () ;public void test ( Instrument i ) ;

public void calibrate ( Instrument i) ;

public int getID () ;} //WeatherStation

Page 39: SECh1214

Slide 39

12.3 Design evolution Hiding information inside objects means that

changes made to an object do not affect other objects in an unpredictable way

Assume pollution monitoring facilities are to be added to weather stations. These sample the air and compute the amount of different pollutants in the atmosphere

Pollution readings are transmitted with weather data

Page 40: SECh1214

Slide 40

Changes required Add an object class called ‘Air quality’ as part of

WeatherStation Add an operation reportAirQuality to

WeatherStation. Modify the control software to collect pollution readings

Add objects representing pollution monitoring instruments

Page 41: SECh1214

Slide 41

Pollution monitoring

NODatasmokeDatabenzeneData

collect ()summarise ()

Air qualityidentifier

reportWeather ()reportAirQuality ()calibrate (instruments)test ()startup (instruments)shutdown (instruments)

WeatherStation

Pollution monitoring instruments

NOmeter SmokeMeter

BenzeneMeter

Page 42: SECh1214

Slide 42

OOD is an approach to design so that design components have their own private state and operations

Objects should have constructor and inspection operations. They provide services to other objects

Objects may be implemented sequentially or concurrently

The Unified Modeling Language provides different notations for defining different object models

Key points

Page 43: SECh1214

Slide 43

Key points A range of different models may be produced

during an object-oriented design process. These include static and dynamic system models

Object interfaces should be defined precisely using e.g. a programming language like Java

Object-oriented design simplifies system evolution

Page 44: SECh1214

Slide 44

10 minute break - a puzzle What is the probability that a randomly

picked triangle contains an obtuse angle ? An angle between 90 and 180 degrees is

called an obtuse angle.

Triangle with an obtuse angle

Triangle without any obtuse angle

Page 45: SECh1214

Slide 45

Solution to the puzzle Every triangle has a unique circum-circle on

which the 3 corners of the triangle lie. A triangle has an obtuse angle, when all the three

corners lie in one half of the circle (same semi-circle).

Reuse the knowledge from last weeks puzzle. The probability that 3 randomly picked points on

the circumference of a circle falling in the same semi-circle is 0.75

Answer is 0.75.

Page 46: SECh1214

Slide 46

Solution to the puzzle fromProf. Greg Allen Solution from first principles. If you fix 2 angles of triangle, its 3rd

angle gets automatically fixed. Red areas represent the cases where

angle A or B is an obtuse angle. Blue area represents the cases where

angles A + B <= 90 and hence angle C is an obtuse angle.

White area represents the cases where angles A + B => 90 and hence angle C <= 90. No angle is obtuse.

Red and Blue areas cover 75% Answer is 0.75.

B

180

180

A

Page 47: SECh1214

Slide 47

Ch 14 - Design with Reuse Building software from reusable components. In most engineering disciplines, systems are

designed by composing existing components that have been used in other systems

Software engineering has been more focused on original development but it is now recognised that to achieve better software, more quickly and at lower cost, we need to adopt a design process that is based on systematic reuse

Page 48: SECh1214

Slide 48

Becoming a Chess Master First learn rules and physical requirements

• e.g., names of pieces, legal movements, chess board geometry and orientation, etc.

Then learn principles• e.g., relative value of certain pieces, strategic value of

center squares, power of a threat, etc.

However, to become a master of chess, one must study the games of other masters• These games contain patterns that must be understood,

memorized, and applied repeatedly

There are hundreds of these patterns

Page 49: SECh1214

Slide 49

Becoming a Software Design Master

First learn the rules• e.g., the algorithms, data structures and languages of

software

Then learn the principles• e.g., structured programming, modular programming,

object oriented programming, generic programming,etc.

However, to truly master software design, one must study the designs of other masters• These designs contain patterns must be understood,

memorized, and applied repeatedly

There are quite a few of these patterns

Page 50: SECh1214

Slide 50

Reuse-based software engineering Application system reuse

• The whole of an application system may be reused either by incorporating it without change into other systems (COTS reuse) or by developing application families

Component reuse• Components of an application from sub-systems to single

objects may be reused Function reuse

• Software components that implement a single well-defined function may be reused

Page 51: SECh1214

Slide 51

Benefits of reuse Increased reliability

• Components exercised in working systems Reduced process risk

• Less uncertainty in development costs Effective use of specialists

• Reuse components instead of people Standards compliance

• Embed standards in reusable components Accelerated development

• Avoid original development and hence speed-up production

Page 52: SECh1214

Slide 52

Requirements for design with reuse It must be possible to find appropriate reusable

components The reuser of the component must be confident

that the components will be reliable and will behave as specified

The components must be documented so that they can be understood and, where appropriate, modified

Page 53: SECh1214

Slide 53

Reuse problems Increased maintenance costs Lack of tool support Not-invented-here syndrome Maintaining a component library Finding and adapting reusable components

Page 54: SECh1214

Slide 54

14.1 Component-based development Component-based software engineering (CBSE) is an

approach to software development that relies on reuse It emerged from the failure of object-oriented

development to support effective reuse. Single object classes are too detailed and specific

Components are more abstract than object classes and can be considered to be stand-alone service providers

The component interface is published and all interactions are through the published interface

Page 55: SECh1214

Slide 55

Component interfaces Provides interface

• Defines the services that are provided by the component to other components

Requires interface• Defines the services that specifies what services must be

made available for the component to execute as specified

Component Provides interfaceRequires interface

Page 56: SECh1214

Slide 56

Printing services component

Provides interfaceRequires interface

Print

PrintService

GetQueue

Remove

Transfer

Register

Unregister

GetPDfile

PrinterInt

Page 57: SECh1214

Slide 57

Component abstractions Functional abstraction

• The component implements a single function such as a mathematical function

Casual groupings • The component is a collection of loosely related entities that might be data

declarations, functions, etc.

Data abstractions • The component represents a data abstraction or class in an object-oriented

language Cluster abstractions

• The component is a group of related classes that work together

System abstraction • The component is an entire self-contained system

Page 58: SECh1214

Slide 58

CBSE processes Component-based development can be integrated into a standard

software process by incorporating a reuse activity in the process However, in reuse-driven development, the system requirements

are modified to reflect the components that are available CBSE usually involves a prototyping or an incremental

development process with components being ‘glued together’ using a scripting language

Designsystem

aachitecture

Specifycomponents

Search forreusable

components

Incorporatediscoveredcomponents

An opportunistic reuse process

Page 59: SECh1214

Slide 59

Development with reuse

Search forreusable

components

Outlinesystem

requirements

Modify requirementsaccording todiscoveredcomponents

Search forreusable

components

Architecturaldesign

Specify systemcomponents

based on reusablecomponents

Page 60: SECh1214

Slide 60

CBSE problems Component incompatibilities may mean that cost

and schedule savings are less then expected Finding and understanding components Managing evolution as requirements change in

situations where it may be impossible to change the system components

Page 61: SECh1214

Slide 61

Application frameworks Frameworks are a sub-system design made up of a

collection of abstract and concrete classes and the interfaces between them

The sub-system is implemented by adding components to fill in parts of the design and by instantiating the abstract classes in the framework

Frameworks are moderately large entities that can be reused• not full applications in their own right• applications are constructed by integrating a number

of frameworks.

Page 62: SECh1214

Slide 62

Framework classes System infrastructure frameworks

• Support the development of system infrastructures such as communications, user interfaces and compilers

Middleware integration frameworks• Standards and classes that support component

communication and information exchange. Eg. CORBA, Microsoft’s COM, DCOM, Java Beans

Enterprise application frameworks• Support the development of specific types of

application such as telecommunications or financial systems. Embed domain knowledge and support end-user applications.

Page 63: SECh1214

Slide 63

Extending frameworks Frameworks are generic and are extended to create

a more specific application or sub-system Extending the framework involves

• Adding concrete classes that inherit operations from abstract classes in the framework

• Adding methods that are called in response to events that are recognised by the framework

Problem with frameworks is their complexity and the time it takes to use them effectively

Page 64: SECh1214

Slide 64

Model-view controller System infrastructure framework for GUI design Allows for multiple presentations of an object and

separate interactions with these presentations MVC framework involves the instantiation of a

number of patterns (eg. Observer discussed later)

Model state

Model methods

Controller state

Controller methods

View state

View methods

User inputsview modification

messages

Model editsModel queries

and updates

Page 65: SECh1214

Slide 65

COTS product reuse COTS - Commercial Off-The-Shelf systems COTS systems are usually complete application

systems that offer an API (Application Programming Interface)

Building large systems by integrating COTS systems is now a viable development strategy for some types of system such as E-commerce systems

Page 66: SECh1214

Slide 66

COTS system integration problems Lack of control over functionality and

performance• COTS systems may be less effective than they appear

Problems with COTS system inter-operability• Different COTS systems may make different

assumptions that means integration is difficult No control over system evolution

• COTS vendors not system users control evolution Support from COTS vendors

• COTS vendors may not offer support over the lifetime of the product

Page 67: SECh1214

Slide 67

Component development for reuse Components for reuse may be specially constructed

by generalising existing components Component characteristics for reusability

• Should reflect stable domain abstractions• Should hide state representation• Should be as independent as possible• Should publish (but not handle) exceptions through the

component interface There is a trade-off between reusability and usability.

• The more general the interface, the greater the reusability but it is then more complex and hence less usable

Page 68: SECh1214

Slide 68

Reusable components The development cost of reusable components is

higher than the cost of specific equivalents. This extra reusability enhancement cost should be an organization rather than a project cost

Generic components may be less space-efficient and may have longer execution times than their specific equivalents

Page 69: SECh1214

Slide 69

14.2 Application families An application family or product line is a related

set of applications that has a common, domain-specific architecture

The common core of the application family is reused each time a new application is required

Each specific application is specialised in some way and may involve writing additional units and adapting some components to meet new demands

Page 70: SECh1214

Slide 70

Application family specialisation Platform specialisation

• Different versions of the application are developed for different platforms

Configuration specialisation• Different versions of the application are created to

handle different peripheral devices Functional specialisation

• Different versions of the application are created for customers with different requirements. E.g. inventory management system for power utility, university labs, library etc

Page 71: SECh1214

Slide 71

A resource management system

Resource database

Resource desc. Screen spec. Report spec.

Add Delete Query Browse Admin Report

User access Program access

Page 72: SECh1214

Slide 72

Inventory management systems Resource database

• Maintains details of the things that are being managed I/O descriptions

• Describes the structures in the resource database and input and output formats that are used

Query level• Provides functions implementing queries over the

resources Access interfaces

• A user interface and an application programming interface

Page 73: SECh1214

Slide 73

Application family architectures Architectures must be structured in such a way to

separate different sub-systems and to allow them to be modified

The architecture should also separate essential facilities of the system from the detailed information (about the resources) and the user access to such information.

Specific layer includes descriptions, screens, reports. Higher layers use these descriptions in their operation

rather than hard-wired info about the resources.

Page 74: SECh1214

Slide 74

Library system The resources being managed are the books in the library Additional domain-specific functionality (issue, borrow,

etc.) must be added for this application

Library holdings database

Resource desc. Screen spec. Report spec.

Add Delete Query Browse Admin Report

Library user access

Issue Return Users

Page 75: SECh1214

Slide 75

14.3 Design patterns A design pattern is a way of reusing abstract

knowledge about a problem and its solution A pattern is a description of the problem and the

essence of its solution It should be sufficiently abstract to be reused in

different settings Well-tried solution to a common problem Description of accumulated wisdom and experience Patterns often rely on object characteristics such as

inheritance and polymorphism

Page 76: SECh1214

Slide 76

Pattern elements 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

Page 77: SECh1214

Slide 77

Multiple displays

Subject

A: 40B: 25C: 15D: 20

Observer 1 Observer 2

0

50

25

A B C D

A

B

C

D

Page 78: SECh1214

Slide 78

The Observer 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 the next slide with UML description Consequences

• Optimisations to enhance display performance are impractical

Page 79: SECh1214

Slide 79

The Observer pattern

Subject Observer

Attach (Observer)Detach (Observer)Notify ()

Update ()

ConcreteSubject

GetState ()

subjectState

ConcreteObserver

Update ()

observerState

return subjectState

for all o in observers o -> Update ()

observerState = subject -> GetState ()

Page 80: SECh1214

Slide 80

Comparing patterns and Frameworks

Patterns and frameworks are highly synergistic concepts, with neither subordinate to the other

Patterns have been characterized as more abstract descriptions of frameworks, which are then implemented in a particular language

Sophisticated frameworks typically embody dozens of patterns

Likewise, patterns have been used to document frameworks

Page 81: SECh1214

Slide 81

Patterns handbook Mature engineering disciplines have handbooks

that describe successful solutions to known problems• e.g., automobile designers don’t design cars using the laws of

physics, they adapt adequate solutions from the handbook known to work well enough

• The extra few percent of performance available by starting from scratch typically isn’t worth the cost

Patterns can form the basis for the handbook of software engineering• If software is to become an engineering discipline,

successful practices must be systematically documented and widely disseminated

Page 82: SECh1214

Slide 82

Design with reuse involves designing software around good design and existing components

Advantages are lower costs, faster software development and lower risks

Component-based software engineering relies on black-box components with well-defined requires and provides interfaces

COTS product reuse is concerned with the reuse of large, off-the-shelf systems

Key points

Page 83: SECh1214

Slide 83

Key points Software components for reuse should be

independent, should reflect stable domain abstractions and should provide access to state through interface operations

Application families are related applications developed around a common core. A generic system is adapted and specialised to meet specific requirements - platform/configuration/functionality

Design patterns are high-level abstractions that document successful design solutions