Download - Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

Transcript
Page 1: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

1 © Telelogic AB Page 1

Bruce Powel Douglass, PhD

Telelogic, Inc.

www.ilogix.com

Real-Time Design Patterns

UML is a trademark or registered trademark of Object Management Group, Inc. in the U.S. and other countries.

Page 2: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

2 © Telelogic AB

Agenda

• Design Process – Where does architecture fit in?

• What is a design pattern?

• Architectural design patterns– Execution Control

– Structure

– Resource Management

– Safety and Reliability

Page 3: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

3 © Telelogic AB

Analysis in ROPES

RequirementsAnalysis

Systems Engineering

Object Analysis

Analysis

ArchitecturalDesign

MechanisticDesign

DetailedDesign

Design

TranslationTesting

Party!

IntegrationTesting

ValidationTesting

Coding

UnitTesting

IterativePrototypes

Page 4: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

4 © Telelogic AB

Analysis

Analysis is the identification of the required properties

of all possible acceptable solutions

Page 5: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

5 © Telelogic AB

Design in ROPES

RequirementsAnalysis

Systems Engineering

Object Analysis

Analysis

ArchitecturalDesign

MechanisticDesign

DetailedDesign

Design

TranslationTesting

Party!

IntegrationTesting

ValidationTesting

Coding

UnitTesting

IterativePrototypes

Page 6: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

6 © Telelogic AB

Design

Design is the selectionof one particular solution which optimizes the setof design criteria with respect to the relative importance of each

Page 7: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

7 © Telelogic AB

Common Design Criteria

• Performance– Average

– Worst-case

– Predictability

• Resource usage– Robustness

– Thread safety

– Minimization of resources (space)

– Minimization of resources (time)

• Safety

• Reliability

• Reusability

• Extensibility & evolvability

• Maintainability

• Time-to-market

• Standard conformance

Quality of Service (QoS) always drives your design

Page 8: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

8 © Telelogic AB

Analysis

• What, not How• Identify all properties that must exist in all acceptable solutions

• Requirements Analysis– Identify black box functionality

– Use case and context views

• Object Analysis– Identify essential object model

– Class, state and scenario views

Page 9: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

9 © Telelogic AB

Design

• How analysis model will be implemented

• Identify and refine the properties of one particular solution• Two approaches

– Elaborative Design

Refine analysis model by adding more detail

– Translative Design

Build a translator that embodies design decisions

Page 10: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

10 © Telelogic AB

Creative Design

Internalization

Pattern Matching

Sequential Analysis

Page 11: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

11 © Telelogic AB

(Physical) Architectural Design

• (Harmony) Architectural Design consists of 5 interrelated model views:– Concurrency and Resource View

– Deployment View

– Distribution View

– Safety and Reliability View

– Subsystem and Component View

Each Architectural View will have its own design patterns.

The complete system architecture is the set of design patterns

used in of the aspects of physical architecture.

Page 12: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

12 © Telelogic AB

Aspects of Architecture

Subsystem and

Component View

Concurrency and

Resource View

Distribution V

iew

Safety and

Reliability View

Deploym

ent

View

Page 13: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

13 © Telelogic AB

Example of Pattern Selection

0

10

20

30

40

50

60

70

80

Worst Case Perf

Worst Case Perf

Safety

Reliability

Memory Usage

Portability

Time to Market

Architectural Patterns:

• Static priority Pattern• Fixed Block Memory Allocation Pattern • Channel Pattern• Triple Modular Redundancy Pattern

Design Criteria ranked by criticality

Safety

Reliability

Memory

Portability

TTM

Page 14: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

14 © Telelogic AB

Example of Pattern Selection (2)

0

10

20

30

40

50

60

70

80

90

Time to Market

Time to Market

Reusability

Simplicity

Performance

Reliability

Safety

Architectural Patterns:

• Recursive Containment Pattern• Cyclic Executive Pattern• Dynamic Memory Pattern• Container-Iterator PatternDesign Criteria ranked by criticality

Reusability

Simplicity

Performance

Reliability

Safety

Page 15: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

15 © Telelogic AB

Mechanistic Design

• Addition and refinement of objects to implement analysis models• Addition of “glue” objects

– Containers and Collections

– Interfaces

– Medium-level policies

– Optimized rendezvous among threads

– Aid reuse by enforcing

• Good abstraction

• Good encapsulation

Page 16: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

16 © Telelogic AB

Detailed Design

• Refinement of details within objects themselves– Visibility

– Internal decomposition of services

– Internal data structuring and typing

– Internal safety and reliability means

• Data redundancy

– Internal implementation policy of associations and object messaging

Page 17: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

17 © Telelogic AB

Design Patterns

• Design patterns are – generalized solutions to recurring optimization problems

– reified structures of object collaboration that reappear in a variety of

contexts

– Parameterized collaborations of objects, where the object roles are the

formal parameters and the objects that play those roles are the actual

parameters when the pattern is instantiated

• UML has introduced a notation to explicitly capture design patterns.• Shown as a dotted ellipse with dotted lines to the collaborating objects or classes

Page 18: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

18 © Telelogic AB

Example Analysis Model Collaboration

Page 19: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

19 © Telelogic AB

Design Pattern: Observer Pattern Specification

Page 20: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

20 © Telelogic AB

Design Pattern: Observer Pattern Instantiation

Page 21: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

21 © Telelogic AB

Why Use Design Patterns?

• Reuse effective design solutions• Provide a more powerful vocabulary of design concepts to developers• Develop “optimal” designs for specific design criteria• Develop more understandable designs

Page 22: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

22 © Telelogic AB

How do I Apply Design Patterns???

1. Construct the initial model

2. Identify the design criteria

3. Rank the design criteria in order of importance

4. Identify design patterns that optimize the system (architectural) or

collaboration (mechanistic) for the critical design criteria at the

expense of the lesser important ones

1. Architectural patterns apply system-wide

2. Mechanistic patterns apply collaboration-wide

3. State behavioral patterns apply object state machine-wide

Page 23: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

23 © Telelogic AB

Architectural Design Patterns

Page 24: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

24 © Telelogic AB

Channel Pattern

• Problem– Efficient execution of a system in which data is successively transformed in a series of steps

– Want to organize and manage a hi-reliability, hi-availability, or safety-critical system that must

provide redundancy of end-to-end behaviors

• Solution– Construct the system as a channel, a large scale subsystem which handles data from acquisition

all the way through dependent actuation. Provide as many independent channels as necessary.

• Consequences– A simple organizational pattern that permits redundancy to be easily added.

– May use additional memory since channels are designed to be independent, requiring replication

(redundancy)

Page 25: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

25 © Telelogic AB

Channel Pattern

Input Filter Output FilterAbstract

Transformation

Output

Sink

«channel»

datum

[raw]

datum

[cooked]

datum

[partially cooked]

"Object in State" notation

in the UML. State is insquare brackets.

Concrete

Transformation

transformacquire issue

Page 26: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

26 © Telelogic AB

Channel Pattern Example

Page 27: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

27 © Telelogic AB

Concurrency Architecture Patterns

Page 28: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

28 © Telelogic AB

Message Queuing Pattern

• Problem– A simple way to request services be performed across thread boundaries in a thread-robust way

• Solution– Queue incoming services in the receiving thread until that thread runs – then dequeue and service

the requests

• Consequences– This approach is simple and supported by most operating systems

– Service responses are delayed until the target thread actually runs, so response may not be timely

– No mutual exclusion problem because requests are serialized

Page 29: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

29 © Telelogic AB

Message Queuing Pattern

Thread

myQ

targetQ

1

1

*

1

Mutex

lock()

release()

Queue

insert()

remove()

Page 30: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

30 © Telelogic AB

Guarded Call Pattern

• Problem– Need timely response to service requests across multiple threads, and the synchronization

across thread boundaries must handle mutual exclusion issues for thread-safe rendezvous

• Solution– Permit calls to methods of object across thread boundaries, but protect those calls with a mutual

exclusion semaphore, 1 semaphore per shared object

• Consequences– A simple solution supported by most operating systems

– Can lead to blocking when the target object is currently locked

– Can lead to unbounded priority inversion unless a priority inversion control pattern is also applied

(e.g. Highest Locker or Priority Inheritance)

Page 31: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

31 © Telelogic AB

Guarded Call Pattern

mutex

BoundaryObjectclient

Client ThreadServer Thread

Server

1

1

*

1 Shared

Resource

*

*

* *

Page 32: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

32 © Telelogic AB

Rendezvous Pattern

• Problem– Need a collaboration structure that allows any arbitrary set of preconditional invariants to be

met for thread synchronization, independent of task phasings, scheduling policies, and

priorities.

• Solution– Reify the rendezvous policy as a class that mediates how the threads collaborate

• Consequences– An easy-to-implement pattern that can implement an arbitrarily complex set of thread

rendezvous preconditions

– Thread Barrier Pattern is a common instantiation of this pattern

Page 33: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

33 © Telelogic AB

Rendezvous Pattern

Rendezvous

Client Thread

*

1reset(void): void

register(callback:address)

release(void): void

Callback

2..*

1{ mapped }

Synch Policy

1

1

notify(void): void

Page 34: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

34 © Telelogic AB

Thread Barrier Pattern Statechart

Synch Policy

Ready

Counting

start synch/

count = 0;

[count>=ExpCount-1]

[else]/

myRendezvous->GEN(evReleaseAll)

/ExpCount = ExpectedCount

evSynch/

++count

Page 35: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

35 © Telelogic AB

Memory Patterns

• Pooled Allocation Pattern• Fixed Sized Buffer Allocation Pattern• Smart Pointer Pattern

Page 36: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

36 © Telelogic AB

Pooled Allocation Pattern

• Problem– In a situation that cannot use dynamic allocation during run time, we

need to use many small objects but we cannot statically allocate their

ownership in the worst case, even though we CAN handle all worst

cases

• Solution– Preallocate pools of small shared objects, giving them to the clients as

necessary, who return them when done

• Consequences– No memory fragmentation

– No unpredictable memory allocation

– Handles more complex situations than the Static Allocation Pattern

Page 37: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

37 © Telelogic AB

Pooled Allocation Pattern

Client1

Generic Pool Manager

initiailize

allocate

release

*

Object

Server

«bind»

pooledClass,

BufferSize: int

Resource Pool Manager

ResourceClass, size

pooledClass*

1freeObject

Page 38: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

38 © Telelogic AB

Fixed-Sized Buffer Pattern

• Problem– In situations complex enough to require dynamic memory allocation,

sometimes we cannot live with memory fragmentation

• Solution– Allocate memory dynamically in fixed sized chunks which are

predetermined to allow us to always satisfy a memory request if any

memory is available

• Consequences– Eliminates memory fragmentation

– Requires static (design) analysis to determine optimal block sizes and

number of sized heaps

– Wastes memory since it is always allocated in fixed sized blocks

Page 39: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

39 © Telelogic AB

Fixed-Sized Buffer Pattern

Memory Segment

Heap Manager Sized Heap

Allocated Block

Free Block

Object Factory

Client

1

*

*

1

1

1

1

*

1

*

*

*

{ allocated and free

blocks in the same

memory segment shall

be all the same size }

free List

Page 40: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

40 © Telelogic AB

Smart Pointer Pattern

• Problem– Pointers are very powerful but induce many kinds of errors. This is because

they do not have a means to ensure pre- and post-conditional invariants

• Solution– Reify the pointers as a class so that access to the pointer behavior can be

controlled via operations that ensure correct behavior

• Consequences– Stops most common pointer errors – dangling pointer, memory leaks,

pointer arithmetic

– Doesn’t work well with cyclic data structures

Page 41: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

41 © Telelogic AB

Smart Pointer Pattern

* 1TargetSmart Pointer

Client

*

rawPtr: Target*

Smart Pointer()

Smart Pointer(tAdd: address)

~Smart Pointer()

access()

referenceCount: int

Target Wrapper

Page 42: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

42 © Telelogic AB

Distribution Patterns

• Observer Pattern• Data Bus Pattern• Proxy Pattern• Broker Pattern

Page 43: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

43 © Telelogic AB

Observer Pattern

• Problem– How to efficiently give up-to-date data to clients in a timely way

• Solution– Have clients subscribe to the server. When new data is available, the

server walks the client list and sends them the new data

• Consequences– Works well with minimal complexity

Page 44: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

44 © Telelogic AB

Observer Pattern

Concrete Subject

Abstract Subject

Notification Handle

Abstract Client

subscribe(*Abstract Client)

unsubscribe(*Abstract Client)

notify()

* 1 1

*

Concrete Client

void accept(data)

Data

value: type

1

1 1

1

{ may refer to the same

instance (pass by

reference) or a copy of

the original (pass by

value) }

Page 45: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

45 © Telelogic AB

Observer Pattern Example

Wheel Sensor

Cruise Control

Speedometer

AntiSpin

Controller

CallbackList

Callback

*

1

1

Speed

1

Speed Client

void accept(s: Speed)

Speed

1

«concrete subject»«abstract client»

«concrete client»

«concrete client»

«concrete client»

«data»«data»

«notif ication handle»

*

1

Page 46: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

46 © Telelogic AB

Proxy Pattern

• Problem– Use an observer pattern across multiple address spaces with a variety of

different servers and clients, isolating away the knowledge of the

infrastructure of the means to communicate

• Solution– Similar to a observer pattern but with client and server proxies to isolate the

required infrastructure

• Consequences– A simple adaptation of the observer pattern

– Good isolation of subject from communications

– Optimizes bus traffic

Page 47: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

47 © Telelogic AB

Proxy Pattern

Abstract Proxy

Client-side Proxy

Notification

HandleAbstract Client

*

1

Concrete Client

void accept(data)

Data

value: type

1

1

1

Concrete Server

1

*

1

server dataclient data

*

client proxy server proxyServer-side Proxy

1

*

Abstract Server

subscribe(*Abstract Client)

unsubscribe(*Abstract Client)

notify()

Local Notification

Handle

Remote Notification

Handle

send()

Page 48: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

48 © Telelogic AB

Proxy Pattern Example

«concrete server»

«concrete client»

Safety

Monitor

Safety Processor

Medical Delivery Processor User Control Processor

Gas Mixer Processor

O2 Flow

Sensor

Inspiration

Controller

O2 Flow

Server Proxy

«server-side proxy»

P2: O2 Flow

Client Proxy

P3: O2 Flow

Client Proxy

P1: O2 Flow

Client Proxy

Histogram

ViewDrug Vaporizer Callback

Callback

Callback

Object ID

«concrete client»

«concrete client»

«local notification

handle»

«local notification

handle»

«local notification

handle»

«remote notification

handle»

«client-side proxy»

«client-side proxy»

«client-side proxy»

*

*

*

*

Communications Bus

«concrete client»

O2 Flow

«data»

Page 49: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

49 © Telelogic AB

Broker Pattern

• Problem– Support a symmetric distribution architecture (as for dynamic load

balancing), and allow objects to find each other without knowing their

locations a priori

• Solution– Add a broker as an object repository, such that when servers run, they

register with the broker; when clients need to access a server, they request

the location of the server from the broker

• Consequences– Good support for symmetric architectures

– Good commercial support with CORBA

Page 50: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

50 © Telelogic AB

Broker Pattern

Abstract Proxy

Client-side Proxy

Notification

HandleAbstract Client

*

1

Concrete Client

void accept(data)

Data

value: type

1

1

1

Concrete Server

1

*

1

server dataclient data

*

client proxy server proxyServer-side Proxy

1

*

Abstract Server

subscribe(*Abstract Client)

unsubscribe(*Abstract Client)

notify()

Local Notification

Handle

Remote Notification

Handle

Broker

Remote Notification

Handle

*

{ may be mediated entirely by

the Broker }

Page 51: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

51 © Telelogic AB

Broker Pattern Example

Page 52: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

52 © Telelogic AB

Broker Pattern Example

ORBFurnace

Interface

Furnace

Thermometer

Interface

Thermometer

Temperature

Controller

Controller

Interface

«concrete server» «concrete server»

«broker»«server-side proxy» «server-side proxy»

«client-side proxy»

«client proxy»

Page 53: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

53 © Telelogic AB

Safety and Reliability Patterns

• Protected Single Channel Pattern• Homogeneous Redundancy Pattern• Heterogeneous Redundancy Pattern• Triple Modular Redundancy Pattern• Monitor-Actuator Pattern

Page 54: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

54 © Telelogic AB

Safety and Reliability

• Reliability is measured by MTBF– MTBF = probability of fault

• Safety is measured by risk– risk = severity * likelihood

• Fault is nonconformant behavior– Error – a design or implementation flaw

– Failure – breakage of something that was previously correct

Page 55: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

55 © Telelogic AB

Safety vs Reliability

SafetyReliability

Systems without a

fail-safe state

Systems wiith

a fail-safe

state

Systems without

safety impact

Page 56: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

56 © Telelogic AB

Protected Single Channel Pattern

• Problem– Provide protection against errors (design flaws) in a cost effective way

• Solution– A variant of the Channel pattern the uses light-weight redundancy to

provide identification of errors

• Consequences– Low design cost

– Low recurring cost

– Not able to continue in the presence of faults

Page 57: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

57 © Telelogic AB

Protected Single Channel Pattern

Input

Processing

Data

Transformation Output

ProcessingInput

Sensor Actuator

Data Validation

control

signal

«channel»

* * * *

*

*

*

1

1

*

* *

1

0,1

successor

transformationpredecessor

transformation

Page 58: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

58 © Telelogic AB

Protected Single Channel Pattern Example

Speed Sensor

Motor

Thermometer

Motor

Rate

ProtectedCRC

CRC

setCRC()

getCRC()

checkCRC()

setRateI()emergencyStop

FilteredSpeed

ProtectedOnesComp

value: int

onesCompvalue: int

setValue()

getValue()

MotorController

ControlRatemeasuredRaterunDuration

setControlRateI()setMeasuredRate()

setRunDuration()

Speed Safety

Monitor

«output processing»

«input processing»

«input processing»

«data transformation»

«data validation»

«input sensor»

«input sensor»

«actuator»

shutdownRate

Temperature Controller

MeasuredTemperature

ShutdownTemperature

Motor Control Channel

«channel»

Page 59: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

59 © Telelogic AB

Homogeneous Redundancy Pattern

• Problem– Provide the ability to continue in the presence of a fault

• Solution– Provide “redundancy in the large” by replicating channels

• Consequences– Low design-time cost

– High recurring cost

– Able to continue in the presence of a failure

– Does not recover from errors

Page 60: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

60 © Telelogic AB

Homogeneous Redundancy Pattern

InputProcessing

OutputProcessing

PrimaryInput

Sensor

Data Validaton

Primary Actuation Channel

ActuationValidation

Primary

Actuator

DataTransformation

Output

Processing

Data ValidationActuation

Validation

Secondary

Actuator

Input

ProcessingSecondary

Input

Sensor

Data

Transformation

Secondary Actuation Channel

1

0,1

successor

transformation

predecessor

transformation

1

0,1successor

transformation

predecessor

transformation

Page 61: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

61 © Telelogic AB

Homogeneous Redundancy Pattern Example

O2 SensorDriver

Gas FlowControlle r

Gas FlowDriver

Primary

O2Sensor

O2 Monitor

Main Flow Control Channe l

Gas FlowMonitor

PrimaryGas

Mixer

Flow SensorDriver

PrimaryFlow

Sensor O2 Flow Rate

O2 Sensor

Driver

Gas FlowController

Gas FlowDriver

Backup

O2Sensor

O2 MonitorGas Flow

Monitor

Backup

GasMixer

Flow Sensor

DriverBackupFlow

Sensor

O2 Flow Rate

Backup Flow Control Channel

successortransformation

predecessor

transformation

predecessor

transformation

successortransformation

«input processing»

«input processing»

«input processing»

«input processing»

«data validation»

«data validation»

«data transformation»

«data transformation»

«outputprocessing»

«outputprocessing»

«actuation validation»

«actuation validation»

«Primary Actuation Channel»

«Secondary Actuation Channel» «data transformation»

successortransformation

«data transformation»

Built In Test

Built In Test

Page 62: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

62 © Telelogic AB

Triple Modular Redundancy Pattern

• Problem– Want to provide protection against single point failures and be able to

continue

• Solution– Replicate the channel three times, run all three in parallel

– If one channel breaks, then the other two will concur

• Consequences– A common solution to redundancy

– Low design cost

– Very high recurring cost

– Good support for failures but not for errors

Page 63: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

63 © Telelogic AB

Triple Modular Redundancy Pattern

inputprocessing

datatransformation

outputprocessing

input

sensorActuator

input

processing

data

transformation

output

processing

inputprocessing

datatransformation

outputprocessing

comparator

Actuation Channel 3

0,1successor

transformation

predecessor

transformation

1

0,1successor

transformation

predecessor

transformation

1

0,1successor

transformation

predecessor

transformation

1

Actuation Channel 2

Actuation Channel 1

Page 64: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

64 © Telelogic AB

Triple Modular Redundancy Pattern Example

wheel

sensor

device driver

data

preprocessing

EngineController

comparator

1

Channel 1

optical

wheel

speedsensor Raw Data Filtered Data

Kalman Filter

1

* *

Train Speed Computation Subsystem

wheel

sensor

device driver

data

preprocessing

1

Channel 2

optical

wheel

speed

sensor Raw Data Filtered Data

Kalman Filter

1

* *

wheel

sensor

device driver

datapreprocessing

1

Channel 3

optical

wheel

speed

sensor Raw Data Filtered Data

Kalman Filter

1

* *

Page 65: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

65 © Telelogic AB

Mechanistic Design Patterns

Page 66: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

66 © Telelogic AB

Fundamental Concepts

• Mechanistic patterns all start with “First, create an object that …”

• The vast majority of design patterns use a combination of two very fundamental concepts:

– Delegation

– Interface

The Singleton design pattern is an exception to this rule.

Page 67: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

67 © Telelogic AB

Delegation

• Delegation is a way to extend the functionality of a class by using an extra class to provide additional functionality.

• It is not always necessary to use Inheritance to extend functionality, often Delegation is more preferable.

With DelegationWithout Delegation

Page 68: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

68 © Telelogic AB

Interface

• This is really what most Design Patterns are based upon. The idea is to keep the things that change, separate from the things that

don’t change.

Pure Virtualoperations

Page 69: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

69 © Telelogic AB

Categories of Mechanistic Design Patterns

• Creational– Control the instantiation or creation process

• Structural– Concerned with how classes and objects work together to form larger

collaborations

• Behavioral– Concerned with algorithms and roles objects play within collaborations

The selection and categorization of patterns used here is based largely on the book Design Patterns: Elements of Reusable Object-Oriented Software by Gamma et. al, 1995

Page 70: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

70 © Telelogic AB

Creational Patterns

• Factory• Factory Method• Prototype• Singleton

Page 71: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

71 © Telelogic AB

Factory Pattern

• Problem

– Provide an interface for creating families of related or dependent objects

• Applicability

– When you want to enforce independence of the system structure from how it is

instantiated

– When a system is to be run on different platforms parts that vary among the

platforms

– When a set of objects are meant to be used together

• Solution

– Create an abstract factory that knows how to create all the related parts; subclasses

of the factory know of to create the parts for a specific platform

• Consequences

– It makes it easy to create platform-specific families of related classes

– It promotes consistency among the product families

– It aids understanding the common ground between families

– It is easy to add new platforms for a set of objects

– It is difficult to extend the factory for new kinds of objects

Page 72: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

72 © Telelogic AB

Factory Pattern

Page 73: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

73 © Telelogic AB

Factory Pattern Example

Page 74: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

74 © Telelogic AB

Factory Pattern Example

NT OS Family

VxWorks OS Family

Page 75: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

75 © Telelogic AB

Structural Patterns

• Adapter• Bridge• Composite• Decorator• Flyweight

Page 76: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

76 © Telelogic AB

Adapter Pattern

• Problem

– You want to adapt the interface of a class to meet a client need

• Applicability

– (Class) When you have an existing class that meets the semantic need but has an

incompatible interface

– (Class) When you want to reuse an existing class in as-yet-determined

circumstances

– (Object)

• Solution

– Create a class subclasses both the expected and actual interfaces and does the

impedance matching, or

– Create an object that refactors and forwards the requests

• Consequences

– Class adapters work with only the specific class not subclasses

– Object adapters work with class and subclasses

– Class adapters introduce only a single object

– Object adapters introduce a new object for every server object

Page 77: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

77 © Telelogic AB

Adapter Pattern (Class)

Page 78: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

78 © Telelogic AB

Adapter Pattern (Object)

Page 79: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

79 © Telelogic AB

Adapter Pattern Example (Class)

Page 80: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

80 © Telelogic AB

Adapter Pattern Example (Object)

Page 81: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

81 © Telelogic AB

Composite Pattern

• Problem

– Want to represent the grouping of smaller primitive semantic objects into larger assemblies

• Applicability

– When you want to represent whole-part hierarchies

– When you want to assign creation-destruction responsibilities

– When the whole is at a higher level of abstraction than the parts

• E.g. System contains subsystems contains sub-subsystems

• Solution

– Use the Composite Class of UML 2.0/Rhapsody

• Consequences

– Very effective way to represent hierarchies at possibly many levels

– Very straightforward way of assigning create-destroy responsibilities

– Specific creation-destruction sequences must be added to the structured class behaviors, if

needed

– Composite is responsible, in general, to orchestrate its parts to deliver services

– The Port Pattern provides explicit delegation w/o Composite delegation

Page 82: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

82 © Telelogic AB

Composite Pattern

Page 83: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

83 © Telelogic AB

Composite Pattern Example

Page 84: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

84 © Telelogic AB

Behavioral Patterns

• Chain of Responsibility• Command• Interpreter• Container-Iterator• Mediator• Memento• Observer• State• Strategy• Specializable (“Template”) Method

Page 85: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

85 © Telelogic AB

Chain of Responsibility Pattern

• Problem

– You want to avoid coupling of a request to a specific receiver by giving more than

one object a chance to fulfill the request

• Applicability

– When the best place to handle a request isn’t always known at design time

– When you want to have multi-level response

– When you want the request handlers to be specified dynamically

• Solution

– Create a chain of objects and pass the request from object-to-object until the

request is fulfilled or until all objects have had a chance to act

• Consequences

– Reduced design-time coupling of classes

– Ability to add request processing dynamically

– There is no guarantee that a request will be handled because there is no grand

oversight

Page 86: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

86 © Telelogic AB

Chain of Responsibility Pattern

Page 87: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

87 © Telelogic AB

Chain of Responsibility Pattern Example

Page 88: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

88 © Telelogic AB

Container-Iterator Pattern

• Problem

– You want to efficiently manage collections and hide the implementation of the collection

• Applicability

– When containment is independent of object semantics

– When you want to support multiple clients of the same collection

– When you want to supply a consistent interface for collection navigation

• Solution

– Reify the collection as an object and provide implementation-free interface for the kind of collection

– Usually implemented as a parameterized class (template)

– Add iterators to support multiple-client navigation over the collection

• Consequences

– Allows extensibility in navigation of collections

– Allows easy changes to types of collections

– Iterators simplify the navigation over the collections

– Multiple clients can simultaneously navigate over the collection

– Note: Rhapsody provides this pattern automatically

Page 89: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

89 © Telelogic AB

Container-Iterator Pattern

Page 90: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

90 © Telelogic AB

Container-Iterator Pattern Example

Page 91: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

91 © Telelogic AB

Container-Iterator Pattern Example

Page 92: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

92 © Telelogic AB

Mediator Pattern

• Problem

– You want to coordinate a complex interaction among a set of objects

• Applicability

– When a set of objects must coordinate in a well-defined but complex manner

– When reusing an object is difficult because it has interactions with a large number other

objects

– When interactive behavior arising from a group of objects should be done without a lot of

subclassing

• Solution

– Reify the interaction as a class that coordinates the interaction with the objects

– The architectural Rendezvous Pattern is a large scale example of this pattern applied to

thread interaction

• Consequences

– Limits subclassing

– Decouples classes within the interacting set

– Abstracts and simplifies object interaction protocols

Page 93: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

93 © Telelogic AB

Mediator Pattern

Page 94: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

94 © Telelogic AB

Mediator Pattern Example

Page 95: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

95 © Telelogic AB

Observer Pattern

• Problem– You want to efficiently notify a set of clients that relevant data has changed

• Applicability– When you want to efficiently notify a set of objects about a value or state

change

– When you want to dynamically add or remove objects to be notified

– When the server should have no knowledge of the client(s)

• Solution– Create a Subject class that provides subscribe() and unsubscribe

operations

– When data changes, notify all subscribed objects

• Consequences– Easy to dynamically add or remove observers

– Supports “broadcast” of state information

Page 96: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

96 © Telelogic AB

Observer Pattern

Page 97: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

97 © Telelogic AB

Observer Pattern Example

Page 98: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

98 © Telelogic AB

Strategy Pattern

• Problem

– You want to apply a family of algorithms and make them interchangeable, even

dynamically so

• Applicability

– When you want to apply an algorithm to different classes

– When you need algorithmic variants

– When you need to vary a strategy or algorithm at run-time

• Solution

– Reify the strategy(ies) as objects and attach them to the appropriate context objects

• Consequences

– Easy management and application of related algorithms

– Alternative to subclassing the context

– Eliminates conditional statements in algorithms

– Allows selection of an optimal algorithmic strategy depending on circumstances

– Some overhead for collaboration between context and strategy

Page 99: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

99 © Telelogic AB

Strategy Pattern

Page 100: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

100 © Telelogic AB

Strategy Pattern Example

Page 101: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

101 © Telelogic AB

Specializable Method Pattern

• Problem– You want to define a skeleton of an algorithm and allow specialized steps

to be subclassed

• Applicability– When the algorithm has a static structure but some steps may differ

depending on the need

– When the algorithm is linearly factorable

• Solution– Define a context class for the algorithm structure and allow subclasses to

modify the steps that may vary

– Aka “Template Method”

• Consequences– Good algorithmic reuse

– Useful for class libraries

Page 102: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

102 © Telelogic AB

Specializable Method Pattern

Page 103: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

103 © Telelogic AB

Specializable Pattern Example

Page 104: Real-Time Design Patterns - West Virginia Universitycommunity.wvu.edu/~hhammar/rts/adv rts/adv rts slides/Bruce_Doug… · Real-Time Design Patterns ... –Requires static (design)

104 © Telelogic AB

Real-Time Pattern References

White papers on real-time, objects, and the UML at www.ilogix.com