Professional Documents
Culture Documents
12 DPF Framework Variability
12 DPF Framework Variability
Plugin, complement
Variation Extension
point point
Framework
Design Patterns and Frameworks
Predecessor Subject
(Figure Chain) (Int. Fig. Observer)
Prof. Uwe Aßmann, Design Patterns and Frameworks
RectangleFigure CompositeFigure
Observer
(Int. Fig. Observer)
ClassFigure RootFigure
Client Figure
(ClassFigure) (ClassFigure)
The Figure Framework, Partially
Instantiated
10
Framework
Editor
Figure Graphics
Predecessor Subject
Prof. Uwe Aßmann, Design Patterns and Frameworks
Observer
(Int. Fig. Observer)
Client Figure
(ClassFigure) (ClassFigure)
The Figure Framework, Fully Instantiated to
an Editor
Framework
11 Editor
Figure Graphics
1..*
Client Observer Subject Child
(ClassFigure) (Figure Observer) 0..* (Figure Observer) (Figure Hierarchy)
RectangleFigure CompositeFigure
Observer
(Int. Fig. Observer)
ClassFigure RootFigure
Client
(RectangleFigure) Root
(FigureHierarchy)
Figure
(ClassFigure)
The Figure Framework, Instantiated to an UML Editor
Framework
UMLEditor
Figure Graphics
Tool
Prof. Uwe Aßmann, Design Patterns and Frameworks
RectangleFigure CompositeFigure
Client Observer
(Figure Hierarchy) (Int. Fig. Observer)
Figure Root
(ClassFigure) (FigureHierarchy)
Client
(RectangleFigure)
ClassDiagram
Client
(ClassFigure)
ClassDiagram
(ClassDiagram)
Merging of Frameworks
13 ► Two frameworks are merged by binding the open roles of
framework A to classes of framework B
– Role constraints have to be respected
► Hence, role models play the bridge between different
frameworks, too.
Prof. Uwe Aßmann, Design Patterns and Frameworks
Client Graphics
(Graphics) (Graphics)
Client Graphics
(Clipping) (Clipping)
Client Polyliner
Prof. Uwe Aßmann, Design Patterns and Frameworks
(Polylining) (Polylining)
Client Texter
(Texting) (Texting)
Client Imager
(Imaging) (Imaging)
Image
Image
(Imaging)
Font
Font
(Texting)
Polygon
Polygon
(Polylining)
The Figure and Graphics Frameworks, Client
Merged Client
(Imaging)
(Clipping)
15
Figure Graphics
Editor
Figure Graphics
Texter
Client (Texting)
(RectangleFigure)
RectangleFigure CompositeFigure Imager
(Imaging)
Figure Successor Parent
(RectangleFigure) (Figure Chain) (Figure Hierarchy) Image
Font
Client
(ClassFigure) ClassFigure RootFigure Font
(Texting)
Client Client Root
(RectangleFigure) (Texting) (FigureHierarchy) Polygon
Figure
Polygon
(ClassFigure) RootClient (Polylining)
(FigureHierarchy)
Limitations of Open Role Instantiation
16 ► [Riehle/Gross] role-based framework instantiation relies on
simple role binding, with role constraints
► Role binding for framework instantiation and merging can be
even more elaborated
Prof. Uwe Aßmann, Design Patterns and Frameworks
12.2 Framework Hook Patterns
17
conceptual pattern
– Pree called this a T&H metapattern, we call this a T&H role model
► A T&H role model has 2 parts:
– A template class (or template role type), which gives the skeleton algorithm of the
framework: Fix, grasps commonalities
– A hook class, which can be exchanged (or: a hook role type which can be bound
to a client class): Variable, even extensible, grasps variability and extension
Role mapping
Subject Observer
T&H in Standard Design Patterns
20 ► Subject and Observer can vary; nothing is fixed
– SortingAlgorithm and AnimationEngine can be exchanged
Prof. Uwe Aßmann, Design Patterns and Frameworks
Role mapping
T&H Pattern
(Metapattern)
Framework
+
Hook Pattern
Standard
Design Pattern
Framework Hook Patterns
23 ► The template-hook role model
– adds more pragmatics to a standard design pattern: information
about commonality and variability. Hence, framework
variation points are described
– The template-hook role model adds more constraints to a
Prof. Uwe Aßmann, Design Patterns and Frameworks
T H
Fixed Part
Block notation:
Framework
Flexible Part:
T H Variation Point
12.3 Delegation-Based
Framework Hook Patterns
25
n
T H T H
imp.generateData(data)
generateData(Data) generateData(Data)
TemplateClass Runtime Scenario
28
Framework
Prof. Uwe Aßmann, Design Patterns and Frameworks
templateMethod() hookMethod()
Prof. Uwe Aßmann, Design Patterns and Frameworks
hookObject.hookMethod()
MoreConcrete MoreConcrete
ConcreteHookClassA ConcreteHookClassB
TemplateA TemplateB
templateMethod() templateMethod() hookMethod() hookMethod()
Implementation A
... hookObject.hookMethod();
Attention: To be a template class,
the templateMethod should
Implementation B
... hookObject.hookMethod(); fulfil a contract!
Ex.: Internationalization as
Dimensional Class Hierarchy with 1-T--H
30
Framework
LayoutAlgorithm Template language Language
Hook
layoutPage() getText()
... layout from left to right
Prof. Uwe Aßmann, Design Patterns and Frameworks
language.getText()
... layout...
MoreConcrete MoreConcrete
English (GB) Chinese
TemplateA TemplateB
layoutPage() layoutPage() getText() getText()
language
LayoutAlgorithm Template Hook Language
layoutPage() getText()
Prof. Uwe Aßmann, Design Patterns and Frameworks
Framework
LayoutAlgorithm Language
Ex.: Multiple Internationalization as
Dimensional Class Hierarchy with n-T--H
32
Framework
languages
LayoutAlgorithm Template Hook Language
*
layoutPage() getText()
... layout from left to right
Prof. Uwe Aßmann, Design Patterns and Frameworks
for l in languages
layout(l.getText())
MoreConcrete MoreConcrete
English (GB) Chinese
TemplateA TemplateB
layoutPage() layoutPage() getText() getText()
languages
LayoutAlgorithm Template Hook Language
*
Prof. Uwe Aßmann, Design Patterns and Frameworks
layoutPage() getText()
LayoutAlgorithm * Language
Observer as n-T—H of a Framework
35
Framework
ConcreteObserver
Subject
ConcreteSubject update () ObserverState =
Subject.getState()
getState() ObserverState
setState()
SubjectState
return SubjectState
Observer Runtime Scenario: Several
Visualizers in Parallel
36
Framework
Prof. Uwe Aßmann, Design Patterns and Frameworks
:SortingAlgorithm :TextVisualizer
register(Observer) update()
unregister(Observer)
notify() :HtmlVisualizer
getState()
setState() update()
:JDKVisualizer
update()
Observer-Based Extensible Frameworks
37
Framework
SortingAlgorithm Visualizer
visualizers
Template Hook
Prof. Uwe Aßmann, Design Patterns and Frameworks
Framework
SortingAlgorithm * Visualizer
Observer
38 ► The Observer pattern is used for extensibility
► With T&H, it becomes clear that Observers are a perfect way to
achieve product lines with new feature extensions:
– Model a critical template algorithm as Subject
(template of the n-T--H)
Prof. Uwe Aßmann, Design Patterns and Frameworks
H1
H2
40
Framework
Prof. Uwe Aßmann, Design Patterns and Frameworks
:Animal :AnimalGroup
:AnimalAge
:AnimalNurture
Extensible Bridge Framework with n-T--H
41
Framework
BusinessObjectCore
Framework
Prof. Uwe Aßmann, Design Patterns and Frameworks
Template
Core Object
* extensions
Hook Extension *
BusinessObjectExtension
n-T—H Makes Bridge Frameworks
Extensible
42 ► An n-T—H framework hook makes dimensional bridge
frameworks extensible with new dimensions at run time
► New extensions in new dimensions can be added and removed
on-the-fly
► Applications
Prof. Uwe Aßmann, Design Patterns and Frameworks
– Business applications
– System software
– 3- and n-tier architectures
T—H Patterns Result in Blackbox
Frameworks
43 ► The main relation between T and H is delegation.
► Hence, when overriding and instantiating H, the framework is
untouched (blackbox framework)
► 1-T—H gives variability
► n-T—H gives extensibility
Prof. Uwe Aßmann, Design Patterns and Frameworks
12.4 The H<=T Recursion
Metapattern
44
pattern (1:n)
H<=T (deep list extension) n-H<=T (deep graph extension)
T part of H H has n T parts
H inherits from T H inherits from T
1-ObjectRecursion/Decorator n-ObjectRecursion/Composite
n
T H T H
*
Template Hook Template Hook
Decorator as 1-H<=T
46 ► All decorator objects have to conform to the template class of
the Decorator pattern
Framework Mini-connector
1
Record
Template mimiced
access()
Prof. Uwe Aßmann, Design Patterns and Frameworks
Hook
TransientRecord PersistentDecorator
access() access()
mimiced.access()
PersistentRead PersistentRecord
OnlyRecord if (!loaded()) load();
access() super.access();
if (!loaded()) load(); access()
boolean loaded() if (modified()) dump():
super.access(); boolean loaded()
boolean modified()
load()
load()
dump()
Ex.: Run-Time Snapshot of Decorator as
Framework Hook Pattern
47 ► Lists extend the framework
Template object
Framework
Prof. Uwe Aßmann, Design Patterns and Frameworks
:TransientRecord
Hook objects
:PersistentRecord :PersistentRecord
Composite as n-H<=T
Framework
Client Component
Prof. Uwe Aßmann, Design Patterns and Frameworks
commonOperation()
add(Component)
remove(Component)
getType(int) *
Template
childObjects
Hook
Leaf Composite
commonOperation() commonOperation()
for all g in childObjects
add(Component)
g.commonOperation()
remove(Component)
getType(int)
Ex. Run-Time Snapshot of Composite as
Framework Hook Pattern
49 ► Part/Whole hierarchies extend the framework
Template object
Framework
Hook objects
Prof. Uwe Aßmann, Design Patterns and Frameworks
:Picture
Node
ComposedPiece CarPart
PieceList
Component AtomicPiece AtomicCarPart
Leaf
Ex. Snapshot of a Production Data System
Framework
:PieceList :Car
HookM TemplateM
T1 T2 T3 Decorator
T1 T2 T3 Compositum
* * *
First facet dimension
H1
Second facet
H2
Third facet
H3
12.5 The TH Unification
Metapattern
55
TH TH TH
n
*
Template Hook Template Hook Template Hook
ChainOfResponsibility as 1-TH
Successor
1
Prof. Uwe Aßmann, Design Patterns and Frameworks
Framework
Hook
Client Worker
Template
Work()
ConcreteWorker1 ConcreteWorker2
Work() Work()
Ex.: Event Handlers
58
Successor
1
Prof. Uwe Aßmann, Design Patterns and Frameworks
Framework
Hook
Client EventHandler
Template
handleEvent()
Logger SecurityHandler
handleEvent() handleEvent()
Ex.: Snapshot of Event Handlers
59
Template object
Prof. Uwe Aßmann, Design Patterns and Frameworks
Framework
Client :Authentication
handleEvent()
:Logger :SecurityHandler
:Personalizer
Hook objects handleEvent() handleEvent()
handleEvent()
Why TH Unification Makes Sense
60 ► If a hook class is the same as the template class,
– Some methods are template methods, others are hook methods
– Together with the template, the hooks can be exchanged
► Template methods in the template class are not abstract
– They are build from referencing hook methods of the hook class
Prof. Uwe Aßmann, Design Patterns and Frameworks
T1 T2 T3
H1
First facet dimension
H2
H3
Second facet (e.g., Age)
H<T T H
Whitebox Framework with H<T
Framework Hook
64 ► Also TemplateMethod can be applied (HookM <= TemplateM)
Framework
Client Worker
Prof. Uwe Aßmann, Design Patterns and Frameworks
Work()
Template
Hook
ConcreteWorker1 ConcreteWorker2
Work() Work()
Whitebox Framework with H<T
Framework Hook
65 ► Also TemplateMethod can be applied (HookM <= TemplateM)
Framework
Client Worker
Prof. Uwe Aßmann, Design Patterns and Frameworks
Work()
Template
Hook
ConcreteWorker1 ConcreteWorker2
Work() Work()
Summary of
T&H Patterns and Framework Hooks
66
Aggregation/Association T H TH
Prof. Uwe Aßmann, Design Patterns and Frameworks
T H T H TH
T H TH
Prof. Uwe Aßmann, Design Patterns and Frameworks
T H T H
TH
1
69 H<T TH
T H TH
Prof. Uwe Aßmann, Design Patterns and Frameworks
T H T 1 H TH 1
T *H T* H TH *
Summary
71
The End