PATTERNS -STRUCTURAL PATTERNS WATTANAPON G SUTTAPAK Software Engineering, School of Information Communication Technology, University of PHAYAO 1
จุดประสงค์การเรียนรู้ เข้าใจรูปแบบของแบบรูปการออกแบบทั้ง 8 ประเภท ประยุกต์ใช้แบบรูปการออกแบบทั้ง 8 ประเภทได้ 2
STRUCTURAL PATTERNS These patterns concern class and object composition Concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalities 1.Adapter 2.Bridge 3.Filter(new) 4.Composite 5.Decorator 6.Façade 7.Flyweight 8.Proxy
ADAPTER PATTERN works as a bridge between two incompatible interfaces. A real life example, card reader(adapter) read memory(object) to laptop(object)
ADAPTER PATTERN
Interface class
ADAPTER PATTERN Implements AdvanceMediaPlayer
ADAPTER PATTERN Implements MediaPlayer
ADAPTER PATTERN demo adapter pattern 9 Result
BRIDGE PATTERN decouple an abstraction from its implementation the two can vary independently. decouples implementation class and abstract class by providing a bridge structure between them. This pattern involves an interface as a bridge functionality of concrete classes independent from interface implementer classes. demonstrating use of Bridge pattern via following example in which a circle can be drawn in different colors using same abstract class method but different bridge implementer classes. 10
BRIDGE PATTERN 11 Shape Square,Triangle, … check duplicate pattern Color Red, Blue, … Shape and Color
BRIDGE PATTERN 12
BRIDGE PATTERN 13
BRIDGE PATTERN 14
BRIDGE PATTERN 15
BRIDGE PATTERN 16
BRIDGE PATTERN 17 Result
FILTER PATTERN filter a set of objects using different criteria combining multiple criteria to obtain single criteria. 18
FILTER PATTERN 19
FILTER PATTERN 20
FILTER PATTERN 21
FILTER PATTERN 22
FILTER PATTERN 23
FILTER PATTERN 24
FILTER PATTERN 25
FILTER PATTERN 26
COMPOSITE PATTERN group of objects in similar way as a single object 27
COMPOSITE PATTERN 28
COMPOSITE PATTERN 29 Result
DECORATOR PATTERN 30 add new properties to existing object without altering structure
DECORATOR PATTERN 31
DECORATOR PATTERN 32 Result
FACADE PATTERN 33 hiding the complexities of the system the client can access the system via interface
FACADE PATTERN 34
FACADE PATTERN 35 Result
FLYWEIGHT PATTERN primary pattern for reduce the number of objects created decrease memory footprint and increase performance demonstrate this pattern by drawing 20 circle of different locations but we'll creating only 5 objects. Only 5 colors are available so color property is used to check already existing Circle objects. 36
FLYWEIGHT PATTERN 37
FLYWEIGHT PATTERN 38
FLYWEIGHT PATTERN 39
FLYWEIGHT PATTERN 40 Result
PROXY PATTERN a class represents functionality of another class In Proxy pattern, we create object having original object to interface its functionality to outer world. 41
PROXY PATTERN 42 Result
PROXY PATTERN 43 Result