Download presentation
Presentation is loading. Please wait.
Published byStewart Hunt Modified over 9 years ago
1
DESIGN PATTERNS -BEHAVIORAL PATTERNS WATTANAPON G SUTTAPAK Software Engineering, School of Information Communication Technology, University of PHAYAO 1
2
จุดประสงค์การเรียนรู้ เข้าใจรูปแบบของแบบรูปการออกแบบทั้ง 12 ประเภท ประยุกต์ใช้แบบรูปการออกแบบทั้ง 12 ประเภทได้ 2
3
BEHAVIORAL PATTERNS communication between object 1.Chain of Responsibility 2.Command 3.Interpreter 4.Iterator 5.Mediator 6.Memento 7.Observer 8.State 9.Null Object(new) 10.Strategy 11.Template Method 12.Visitor
4
CHAIN OF RESPONSIBILITY PATTERN This pattern creates a chain of receiver objects for a request decouples sender and receivers of a request base on type of request each receiver contains reference to another receiver. If one object cannot handle the request then it passes the same to the next receiver and so on. 4
5
CHAIN OF RESPONSIBILITY PATTERN 5
6
6
7
7 Result
8
COMMAND Passing data(object) to invoker object. Invoker object pass the command to the corresponding object The object executes the command. 8
9
COMMAND 9
10
10
11
COMMAND 11 Result
12
INTERPRETER Evaluate language grammar or expression. Use in SQL parsing, symbol processing engine etc. 12
13
INTERPRETER 13
14
INTERPRETER 14
15
INTERPRETER 15 Result
16
ITERATOR Iterator pattern is very commonly used design pattern in Java and.Net programming environment. This pattern is used to get a way to access the elements of a collection object in sequential manner without any need to know its underlying representation. 16
17
ITERATOR 17
18
ITERATOR 18
19
ITERATOR 19 Result
20
MEDIATOR Used to reduce communication complexity between objects(classes) a mediator class which normally handles all the communications between different classes and supports easy maintainability of the code by loose coupling Ex.Chat Room multiple users can send message to Chat Room Chat Room show the messages to all users 20
21
MEDIATOR 21
22
MEDIATOR 22 Result
23
MEMENTO Restore state of an object to a previous state. Ex. Memento there are 3 classes : Memento, Originator and CareTaker. Memento contains state of an object to be restored. Originator creates and stores states in Memento objects. Caretaker object which is responsible to restore object state from Memento. 23
24
MEMENTO 24
25
MEMENTO 25
26
MEMENTO 26 Result
27
OBSERVER Case : one to many relationship between objects Such as if one object is modified, its dependent objects are to be notified automatically. Implementation There are 3 actor classes : Subject, Observer and Client Subject, an object having methods to attach and de-attach observers to a client object Client extending the abstract class the Observer. 27
28
OBSERVER 28
29
OBSERVER 29
30
OBSERVER 30 Result
31
OBSERVER 31
32
STATE 32 a class behavior changes based on its state.
33
STATE 33
34
STATE 34 Result
35
NULL OBJECT 35 Checking NULL object instance.
36
NULL OBJECT 36
37
NULL OBJECT 37 Result
38
STRATEGY 38 Problem : various objects was called in same method.
39
STRATEGY 39
40
STRATEGY 40 Result
41
TEMPLATE 41 Create abstract class : template to execute its methods.
42
TEMPLATE 42
43
TEMPLATE 43 Result
44
VISITOR Visitor class changes the executing algorithm of an element class. Execution algorithm of element varies to visitor varies Element object accept the visitor object so that visitor object handles the operation on the element object. 44
45
VISITOR 45
46
VISITOR 46
47
VISITOR 47 Result
48
VISITOR 48 ComputerPartVisitor can it be removed? but why not? Do you remember Couple and Cohesion?
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.