Professional Documents
Culture Documents
Design Patterns as
Role Models
1
Prof. Dr. U. Aßmann 1) Design Patterns as Role
Models
Chair for Software
Engineering 2) Composition of Design
Patterns with Role Models
Faculty of Informatics
3) Effects of Role Modeling in
Dresden University of Frameworks
Technology
4) Optimization of Design
WS 17/18 - Nov 27, 2017 Patterns
Lecturer: Dr. Sebastian Götz
1997-1-1.pdf
Goal
Observer Subject
Observer Subject
StateChange EventPort
Participants of Patterns form Role Models
HandlerClient Handler
Successor Predecessor
TailClient Tail
NodeClient Node
Parent Child
RootClient Root
Composing Role Models
Observer Subject
(Observer) (Observer)
Prof. Uwe Aßmann, Design Patterns and Frameworks
Client Node
(Composite) (Composite)
Parent Child
(Composite) (Composite)
RootClient Root
(Composite) (Composite)
Core Role Diagrams of Several Patterns
Adapter Adaptee
Prof. Uwe Aßmann, Design Patterns and Frameworks
Component Decorator
Mediator Colleague
Subject Observer
Adjustments to Riehle's Notation
13
Observer,
Manager Subordinate
Mediator
DirectorClient Director
Example: Bureaucracy
16 DrawingEditor FigureItem
Client Node
(Composite) (Composite)
HandlerClient Handler
(Chain) (Chain)
Prof. Uwe Aßmann, Design Patterns and Frameworks
Group Circle
Parent Child
(Composite) (Composite)
Mediator Colleague
Window Figure (Mediator) (Mediator)
RootClient Root
Subject Observer
(Composite) (Composite)
(Observer) (Observer)
TailClient Tail
Sucessor Predecessor
(Chain) (Chain)
(Chain) (Chain)
Application of Bureaucracy
Observer 1 Observer 2
ModelClient Model
Role-Class Model of MVC
Composed LeafView
View
Parent Child
(Composite) (Composite)
Root
View
Root
(Composite)
This Closes a Big Loop
patterns
► Today, MVC can be explained as composed role model of other
design patterns
Riehle-Gross Law On Composite Design
Patterns
22
The
Therole
rolemodel
modelofofaacomposite
compositedesign
designpatterns
patternsisiscomposed
composedofofthe
the
role models of their component design patterns
role models of their component design patterns
Prof. Uwe Aßmann, Design Patterns and Frameworks
► Consequences
– Complex patterns can be easily split into simpler ones
(decomposition)
– Variants of patterns can more easily be related to each other
(variability of patterns)
● e.g., ClassAdapter and ObjectAdapter
– Template&Hook conceptual pattern can be explained as role
model (see next chapter)
11.2.3 Composition of Simple
Variability Patterns
23
25 ► In a class,
– A kernel method
implements the feature
directly on the attributes of
the class, calling no other
method
Prof. Uwe Aßmann, Design Patterns and Frameworks
Caller Callee
– A derived method is
implemented by calling only
kernel methods
► Caller and callee role have to
be bound to the same class
(as the purpose is to have
class-internal method calls)
Derived Method and TemplateMethod
26 ► TemplateMethod is a
DerivedMethod that has Caller Callee
– an additional
Template/HookMethod role
model
Prof. Uwe Aßmann, Design Patterns and Frameworks
– Inheritance hierarchy on
right side (implied by role-
class inheritance
constraint) TemplateMethod
– The template role implies
no hierarchy on left side Template Hook
Caller Callee
CalleeDescendant
Objectifier and Strategy
27 ► Objectifier has
Objectifier
– A prohibition constraint on
Caller and Callee (instead
Caller Callee
of equivalence)
– No template role
Prof. Uwe Aßmann, Design Patterns and Frameworks
Descendant
TemplateClass
28 ► TemplateClass is an
Objectifier with TemplateClass
– An additional Template/ TemplateM HookM
HookMethod role model
– TemplateMethod role Caller Called
Prof. Uwe Aßmann, Design Patterns and Frameworks
implies no hierarchy
on left side
– HookMethod role implies
inheritance hierarchy on CalleeDescendant
right side
– No client or algorithm role,
otherwise like Strategy
DimensionalClassHierarchies
29 ► DimensionalClassHierarchies
is a TemplateClass
– With left hierarchy
constraint
TemplateM HookM
Prof. Uwe Aßmann, Design Patterns and Frameworks
Caller Called
CallerDescendant CalleeDescendant
Bridge
30 ► Bridge is a
DimensionalHierarchies with
– Abstraction/Implementation Abstraction Implementation
roles instead of T&H
– No template/hook role Caller Called
Prof. Uwe Aßmann, Design Patterns and Frameworks
CallerDescendant CalleeDescendant
Creational Patterns
TemplateM HookM
Caller Callee
CalleeDescendant
Remember: Relation TemplateMethod,
TemplateClass, Strategy, Observer
32
More specific patterns (with more intent, more pragmatics, specific role denotations)
Dimensional
TemplateMethod TemplateClass ClassHierarchies
T&H Metapatterns
Facade
Iterator
Prof. Uwe Aßmann, Design Patterns and Frameworks
Bridge
FactoryMethod
Command
Flyweight
Mediator Adapter Decorator
Reuse
Prof. Uwe Aßmann, Design Patterns and Frameworks
Reuse
0&1
Second dimension
Third dimension
Merging dimensions of Facet/Layered
Frameworks
38 ► If the dimensions are seen as role models, it can be chosen to
merge them, i.e., the role models
► Here: merge second and third dimension into one physical
implementation
Prof. Uwe Aßmann, Design Patterns and Frameworks
Reuse
0
Core dimension: Abstraction Framework
Reuse
0&1
First dimension
Reuse
0-3
Second dimension
Third dimension
Role Models and Layered Frameworks
Reuse
Prof. Uwe Aßmann, Design Patterns and Frameworks
Reuse
0&1
Second layer
Third layer
Merging Dimensions/Layers of
Dimensional/Layered Frameworks
40 ► When two layers are merged, the variability of a framework
decreases
► But its applications are more efficient:
– Less delegations (less bridges)
– Less allocations (less physical objects)
Prof. Uwe Aßmann, Design Patterns and Frameworks
Reuse
Prof. Uwe Aßmann, Design Patterns and Frameworks
Reuse
0&1
Reuse
0
Core dimension: Application
Reuse
0&1
View
Reuse
0-3
Controller
Model
11.4 Optimization of Design
Patterns with Role Models
43
44
Whenever
Wheneveryou
youneed
needaavariant
variantofofaadesign
designpattern
patternthat
thatisismore
moreefficient,
efficient,
investigate
investigate its role model and try to merge the classes of theroles
its role model and try to merge the classes of the
Prof. Uwe Aßmann, Design Patterns and Frameworks
roles
► Effect:
– Less variability
– Less runtime objects
– Less delegations
Original Role-Class Model of MVC
Composed LeafView
View
Parent Child
(Composite) (Composite)
Root
View
Root
(Composite)
Optimized Role-Class Model of MVC
Composed LeafView
View
Parent Child
(Composite) (Composite)
Root
View
Root
(Composite)
The End: Summary