patterns -structural patterns wattanapon g suttapak software engineering, school of information...

43
PATTERNS -STRUCTURAL PATTERNS WATTANAPONG SUTTAPAK Software Engineering, School of Information Communication Technology, University of PHAYAO 1

Upload: rachel-berry

Post on 18-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

1

PATTERNS-STRUCTURAL

PATTERNS

WATTANAPONG SUTTAPAKSoftware Engineering, School of Information Communication Technology,University of PHAYAO

2

จุ�ดประสงค์การเร�ยนร� �

เข้�าใจุร�ปแบบข้องแบบร�ปการออกแบบทั้��ง 8 ประเภทั้

ประย�กต์ใช้�แบบร�ปการออกแบบทั้��ง 8 ประเภทั้ได�

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. Adapter2. Bridge3. Filter(new)4. Composite

5. Decorator6. Façade7. Flyweight8. 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

ADAPTER PATTERN Interface class

ADAPTER PATTERN Implements AdvanceMediaPlayer

ADAPTER PATTERN Implements MediaPlayer

9

ADAPTER PATTERN demo adapter pattern

Result

10

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.

11

BRIDGE PATTERN• Shape Square ,Triangle, …

• check duplicate pattern

• Color Red, Blue, …

• Shape and Color

12

BRIDGE PATTERN

13

BRIDGE PATTERN

14

BRIDGE PATTERN

15

BRIDGE PATTERN

16

BRIDGE PATTERN

17

BRIDGE PATTERN

Result

18

FILTER PATTERN•filter a set of objects

•using different criteria

•combining multiple criteria to obtain single criteria.

19

FILTER PATTERN

20

FILTER PATTERN

21

FILTER PATTERN

22

FILTER PATTERN

23

FILTER PATTERN

24

FILTER PATTERN

25

FILTER PATTERN

26

FILTER PATTERN

27

COMPOSITE PATTERN group of objects in similar way as a single object

28

COMPOSITE PATTERN

29

COMPOSITE PATTERN Result

30

DECORATOR PATTERN add new properties to existing object without altering structure

31

DECORATOR PATTERN

32

DECORATOR PATTERN Result

33

FACADE PATTERN hiding the complexities of the system

the client can access the system via interface

34

FACADE PATTERN

35

FACADE PATTERN

Result

36

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.

37

FLYWEIGHT PATTERN

38

FLYWEIGHT PATTERN

39

FLYWEIGHT PATTERN

40

FLYWEIGHT PATTERNResult

41

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.

42

PROXY PATTERNResult

43

PROXY PATTERNResult