Download presentation
Presentation is loading. Please wait.
Published byBrian Jordan Modified over 9 years ago
1
Design Pattern Dr. Zhen Jiang West Chester University E-mail: zjiang@wcupa.edu url: www.cs.wcupa.edu/~zjiang
2
Outline Introduction Creational Patterns Structural Patterns Behavioral Patterns
3
Introduction A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object- oriented design Creational design patterns abstracts the instantiation process Structural patterns are concerned with how classes and objects are composed to form larger structures. Behavioral patterns are concerned with algorithms and assignment of responsibilities between objects.
4
Creational Pattern Abstract factory Builder Factory Method Prototype Singleton
5
Abstract Factory Client WidgetFactory Motif Consider a user interface (client, windows and ScrollBar) that supports (creates) multiple look- and-feel standards. PMW Windows PMWMotif ScrollBar PMWMotif ?
6
Abstract Factory Client AbstractFactory Factory1Factory2 ProductA PA2PA1 ProductB PB2PB1
7
Abstract Factory Shopping, interlibrary, …
8
Builder Reader/User Add a new conversion? Converter ACSWidget TextPicture
9
Builder Reader/User Builder ConcreteBuilder Product
10
Builder Add a new tool, new course, new equipment, …
11
Factor Method For creating objects Drink, Drug, vegetables, gardening, … Creator Product ConcreteProduct ConcreteCreator
12
Prototype Provide an abstract tool for defining items like those in the palette. Windows creation Prototype Client movement clone Prototype1 clone Prototype2 clone
13
Singleton For some classes to have exactly one instance Examples?
14
Structural Pattern Adapter Bridge Composite Decorator Façade Flyweight Proxy
15
Adapter For existing and unrelated classes working in an application that expects classes with a different and incompatible interfaces (Builder?) Unix process, file system, … Target Client Adapter request Adaptee implementation
16
Bridge Inheritance binding (Builder? AbstractFactory?) Windows (their structure and implementation), Database? RefinedAbstraction Abstraction Implementor IAIB
17
Composite Group components Component LeafComposite
18
Composite aComposite(is aComponent) aComponent aLeaf aComposite aComponent aLeaf
19
Decorator Specifying the responsibility of certain group, build an transparent interface to component’s client Teaching, GA, and Instructor Component LeafDecorator DADB ops
20
Facade Simplifying interface to more general facilities of subsystems. (AbstractFactory, FactorMethod, Bridge) Current screen status of Windows? Facade
21
Flyweight For sharing resource Client FlyWeight ConcreteFlyWeight
22
Flyweight aClient aFlyWeight aCF
23
Flyweight Paragraph and Keys of keyboard?
24
Proxy Access control and reference Subject RealSubject Proxy aClient aProxy aRS
25
Proxy Network Service?
26
Behavioral Pattern Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor
27
Chain of Responsibility Decouple senders and receivers (sequence? ) Steps, courses, … Handler aHandler
28
Command Request, command, …? Dos/Shell command, file I/O, user interface, …? InvokerCommand ConcreteCommandReceiver
29
Interpreter Grammar Composite? Formal language L=a|bC; C=e|cC. (sample statement: a, b, bc, bcc, …
30
Iterator Access without exposing any internal structure Interface FactorMethod
31
Mediator Distribution of behavior among objects AbstractFactory Mediator ConcreteMediator Colleague CC1CC2
32
Memento Record the internal state (checkpoints) Tests of course, firewall, …? OriginatorMemento Caretaker
33
Observer Maintain consistency Observer calls Getstatus( ) Ordering, TCP communication, … Subject ConcreteSubject Observer ConcreteObserver
34
State Conditional statements Used in Command, Memento, Observer, … Project, study, …, Context State ConcreteStateA ConcreteStateB
35
Strategy Builder, Prototype, Bridge, Command, State. Hollywoodsquare, Chess, searching and sorting (for example, shell), … Context Strategy ConcreteStrategyA ConcreteStrategyB
36
Template Method A template method defines an algorithm in terms of abstract operations that subclasses override to provide concrete behavior Inheritance (generalization), virtual function Operations (searching and sorting) in Template class (Template Stack, Template Queue). AbstractClass ConcreteClass
37
Visitor Packaging related operations from each class in a separate object, called a visitor, and passing it to elements of the abstract syntax tree as it’s traversed. Visitor ConcreteVisitorA ConcreteAcceptA ConcreteAcceptB ConcreteAcceptA ConcreteVisitorB ConcreteAcceptB
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.