Software Design
Patterns
Email: [email protected]
Design Patterns Prof. Walaa Khaled 1
Design Patterns Space
Design Patterns Prof. Walaa Khaled 2
Structural Patterns
–Proxy
–Decorator
–Adapter
–Façade
–Flyweight
–Composite
–Bridge
Design Patterns Prof. Walaa Khaled 3
Structural Patterns
–Proxy
–Decorator
–Adapter
–Façade
–Flyweight
–Composite
–Bridge
Design Patterns Prof. Walaa Khaled 4
Flyweight Pattern
Use sharing to support large numbers of fine-grained
objects efficiently
Design Patterns Prof. Walaa Khaled 5
6
Flyweight Design Pattern Example
7
8
9
Flyweight Pattern
Lets you fit more objects into the available RAM by sharing
common parts of the state between multiple objects, instead
of storing all of the data in each object individually
1
Design Patterns Prof. Walaa Khaled 0
Flyweight Design Pattern Example
1
1
Stop storing the state that rarely changes inside the
objects. But instead, move it into a separate object
12
It stores the intrinsic state of the object
This state is invariant context-independent shareable and never altered at
runtime
13
14
15
Design Patterns Prof. Walaa Khaled
Flyweight Pattern
1
Design Patterns Prof. Walaa Khaled 6
Flyweight Pattern UML
17
Structural Patterns
–Proxy
–Decorator
–Adapter
–Façade
–Flyweight
–Composite
–Bridge
1
Design Patterns Prof. Walaa Khaled 8
Composite Pattern
allows you to compose objects into tree structures to
represent part-whole hierarchies. Composite lets clients treat
individual objects and compositions of objects uniformly
1
Design Patterns Prof. Walaa Khaled 9
Using a composite structure, we can apply the same operations over both
composites and individual objects. In other words, in most cases, we can
ignore the differences between the compositions of objects and individual
objects.
20
21
Composite Pattern Example (Design Menu)
2
2
23
24
25
26
27
28
Bridge Pattern
“Decouple an abstraction from its implementation so
that the two can vary independently”
In other words, Decoupling the interface from
implementation and hiding the implementation detail of
abstraction from the client is the main objective of the
bridge design pattern.
2
Design Patterns Prof. Walaa Khaled 9
Example scheduling in OS (without
Bridge Pattern)
30
Schedule
Round Robin FCFS
RR_Windows RR_Linux FCFS_Windows FCFS_Linux
31
ScheduleAbst Has a ImplemenAbst
RR FCFS Windows Linux
32
Bridge Pattern UML
33
Bridge Pattern Example
Before Bridge Pattern
After Bridge Pattern
3
4
Bridge Pattern Example
35
36
37
38