Lecture 7 (5-12-2022)
Lecture 7 (5-12-2022)
Patterns
Email: [email protected]
–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
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
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
2
Design Patterns Prof. Walaa Khaled 9
Example scheduling in OS (without
Bridge Pattern)
30
Schedule
31
ScheduleAbst Has a ImplemenAbst
32
Bridge Pattern UML
33
Bridge Pattern Example
3
4
Bridge Pattern Example
35
36
37
38