Date post: | 04-Jan-2016 |
Category: |
Documents |
Upload: | barnaby-berry |
View: | 212 times |
Download: | 0 times |
Object Oriented Software Engineering
Chapter 16 and 17 review2014/06/03
Pattern’s both side
• Good sides: help management way• Downsides: going to create more class with
don’t know.
3 categories
• Creational • Structural • Behavioral
There are more than 23 pattern: MVC…
Copyright {c} 2014 by the McGraw-Hill Companies, Inc. All rights Reserved.
16-4
Situation Specific Patterns
Creational Patterns• Abstract factory• Builder• Factory method• Prototype• Singleton
Structural Patterns• Adapter• Bridge• Composite• Decorator• Facade• Flyweight• Proxy
Behavioral Patterns• Chain of responsibility• Command• Interpreter• Iterator• Mediator• Memento• Observer• State• Strategy• Template method• Visitor
I. Creational 1. abstract factory
• Many family of codes can categories into many categories. E.g. two family belong to factory and the output is produce product.
16-5
I. Creational 2. builder
• To build sth or construct sth which is complex and compose tiny product.
• Combine product into one and process is similar
• When client request, director get request, each builder build one product which compose many tiny product.
I. Creational 3. factory method
• Group product into one• Based on parameter/ type• Client ask give me “cat”(parameter)• Same parameter will get same product
Animal
Cat Dog
I. Creational 3. prototype
• Refer to original one to build• Construction is complex; therefore; don’t build
from beginning(mean build only once.) • Help change/ want to make change1. Shallow clone: same as original, new and
original both change.2. Deep clone: create prototype, clone all
relationship. New change & keep original(copy on write)
I. Creational 4. singleton
• Create thing at most one (0…1)• Make sth • Do sth
1. Abstract factory’s sub class could be singleton2. Combine with Builder 3. Combine with template
II. Structural 1. adapter
• Often see adapter in the world• We need data from system, but format will be
different. We need to create new interface to extract existing system and combine with user.
• Adapter make system compatible
• Class adapter: only one• Object adapter: more than one, flexible
II. Structural 2. bridge
• Both side(abstract & implementation) to communicate each other
• Choose which one to implement ==choose which one to marry
II. Structural 3. composite
• We want to compose sth• Leaf: terminal and smallness one• Component: has leaf• Composite: has instance• Data structure: recursive, combine• Know how to decompose
II. Structural 5. decorator
• Decorate something• we have based/plain/no decoration class, and want to
put sth on it. • Flexible to add sth we need on it• Decorator is abstract• Component is interface
• http://puremonkey2010.blogspot.tw/2010/11/oo-decorator-pattern.html
II. Structural 5. façade
• Singleton• Know each component will feedback to you
II. Structural 6. flyweight
• You need to create 1000 object(all the same)• Check out the pool(unique in pool)• Intrinsic(constant): save in memory, reuse
many times• Extrinsic: we will not save.(at client…)• stateless
II. Structural 7. proxy
• Surrogate of real one, take place of real one.• Representative of real one, in place of real one• Placeholder• Purpose:1. Protect: need to know user(define first) to authorize, give key
to user2. Virtual proxy: consume a lot of time, if request yes→ display,
no→create3. Remote proxy:SOA4. Smart proxy: when user want to access sth, count how many
times real one is asked, if nobody ask then free the memory.
III. Behavioral 1. chain of responsibility
• Naming is important• Each component on chain have responsibility
to do sth• Define first one and successor(predecessor)• E.g. We have 5 handler on chain, give one
problem for them, pass the problem until solve problem, other is exception. Our design not be solve all problem.
III. Behavioral 2. command
• Create sth and object behave• Invoker group all command• Command execute, if is receiver A, go with A• Undo command(not unlimited)
III. Behavioral 3. interpreter
• Have rule, grammar to perform sth• We can get data based on grammar• Input>
rule: parse / segment / format analyze> output
III. Behavioral 4. iterator
• Traverse sth, want to display or save in different Database
• We don’t want to expose structure, but we want to do structure
• Template: if you have next one, then do sth.
III. Behavioral 5. mediator
• Coordinator to reduce communication• E.g. stock market• Observer: stock market change, notify user
III. Behavioral 6. memento
• We have object• when someone need previous versions, ask
caretaker to get• Originator• Memento
III. Behavioral 7. observer
• Subject is a content, observer subscribe sth.• Many observer interesting one
target(1..many)• Object change, notify subscriber• Reactor design pattern: (*…*) (many…many)
III. Behavioral 8. state
• Class is active, many status define next state
III. Behavioral 9. strategy
• Client can select strategy same text different encryption(algorithm perform differently)
III. Behavioral 10.template method
• Boil> Fried• Don’t call us , we’ll can you(hollywood
principle)
III. Behavioral 11.visitor
• Knock your door, don’t expose structure.• Use iterator to traverse different structure• Composite: to segment leaf(knock the leaf)• If you have lot of operation differently• High cohesion• Want to format sth, display it
16-28
Process for Applying Patterns
16-29
Case Study: Design a State Diagram Editor
reference
16-30