COP 3331 Object Oriented Analysis and Design Chapter 10 Patterns PowerPoint PPT Presentation

presentation player overlay
1 / 20
About This Presentation
Transcript and Presenter's Notes

Title: COP 3331 Object Oriented Analysis and Design Chapter 10 Patterns


1
COP 3331 Object Oriented Analysis and
DesignChapter 10 Patterns
  • Jean Muhammad

2
Overview
  • Abstract Factory Pattern
  • Prototype Pattern
  • Builder Pattern
  • Command Pattern
  • Adapter Pattern
  • Composite Pattern(8.3.2)

3
Abstract Factory
  • Category Creational Design Pattern
  • Intent Provide an interface for creating a
    family of related or dependent objects without
    specifying their concrete classes
  • Applicability Use this pattern when
  • a system should be created independent of its
    components or products.
  • a system should be configurable with one of
    multiple interchangeable families of products.
  • a family of related products should not be mixed
    with similar products from different families.
  • only the interfaces of the products are exposed,
    while the implementation of the products is not
    revealed.

4
Abstract Factory
  • Participants in the Abstract Factory Pattern
  • AbstractFactory Defines methods that create
    abstract products.
  • ConcreteFactory Implements methods that create
    concrete methods
  • AbstractProduct Defines the interface for a
    type of product and may provide default
    implementation
  • ConcreteProduct Defines a product to be created
    by the corresponding concrete factory and
    implements the AbstractProduct interface.
  • Client Uses only AbstractFactory and
    AbstractProduct

5
AbstractFactory makeProductA() makeProductB()
Client
AbstractProductA
ConcreteFactory1 makeProductA() makeProductB()
ConcreteFactory2 makeProductA() makeProductB()
ConcreteProductA1
ConcreteProductA2
AbstractProductB
ConcreteProductB1
ConcreteProductB2
6
Prototype
  • Category Creational Design Pattern
  • Intent To specify the kinds of objects to create
    using prototypical instance and create new
    instances by cloning this prototype
  • Applicability Use this pattern when
  • a system should be independent of how its
    components or products are created
  • the classes to instantiate are specified at
    run-time
  • you want to avoid building a class hierarchy of
    factories that parallels the class hierarchy of
    products.

7
Prototype Design Pattern
  • Participants in the Prototype Pattern
  • Prototypewhich defines interfaces of objects to
    be created
  • ConcretePrototype Implements prototype interface
  • Client Creates instances by cloning the
    prototype.

8
Cloneable
Client prototype aMethod()
Prototype clone()
p prototype.clone()
ConcretePrototype1 clone()
ConcreteProtype2 clone()
9
Builder Design Pattern
  • Category Creational Design Pattern
  • Intent To separate the construction of a complex
    object from the implementation of its parts so
    that the same construction process can create
    complex objects from different implementation of
    parts
  • Applicability Use this pattern when
  • Creating complex objects should be independent of
    the parts.
  • the construction process should allow various
    implementations of the parts used for
    construction.

10
Building Pattern
  • Participants in the Builder Pattern
  • Builder Defines interface for creating parts.
  • ConcreteBiulder Constructs and assemble parts.
  • Director Constructs a product using the Builder
    interface
  • Product Represents the complex object under
    construction.

11
Director Product buildProduct()
Builder buildPart()
ConcreteBuilder1 buildPart()
ConcreteBuilder2 buildPart()
Product
12
Command Design Pattern
  • Category Behavioral Pattern
  • Intent Encapsulate the action of an object, so
    that action can be passed as parameters, queued,
    and possibly undone.
  • Also known as Action
  • Applicability Use this pattern when
  • Actions need to be passed as parameters.
  • Actions need to be queued and then executed later
  • Actions may need to be undone

13
Command Design Pattern
  • Participants in the Command Design Pattern
  • Command Defines an interface to perform or undo
    an action
  • Receiver Knows how to perform the action
  • ConcreteCommand Delegates the execution of the
    action to the Receiver
  • Client Creates the concrete commands and binds
    the concrete commands to their receivers
  • Invoker Ask the command to carry out the action

14
Command execute()
Client
Invoker
Receiver action()
ConcreteCommand execute()
receiver.action()
15
Adapter Pattern
  • Category Structural Design Pattern
  • Intent Convert the interface of a class into
    another interface that clients expect
  • Also known as Wrapper and confused with a bridge
  • Applicability Use this pattern when
  • To use an existing class with an interface
    different from the desired interface

16
Adapter Pattern
  • Participants in the Adapter Pattern
  • Target Defines the interface used by the client
  • Client Uses objects conforming to the Target
    interface
  • Adaptee the existing class to be re-used
  • Adapter Which adapts the interface of the
    Adaptee to Target.

17
Client
Target doTask()
Adaptee performTask()
Adapter doTask()
performTask()
18
Design Composite
  • Category Structural Design Pattern
  • Intent Compose objects into tree structures to
    represent a part-whole hierarchy. Composite lets
    clients treat individual objects and composite
    objects.
  • Applicability Use this pattern when
  • you want to represent a part-whole hierarchy of
    objects.
  • When you want clients to be able to ignore the
    difference between composite objects and
    individual objects.

19
Composite Design Pattern
  • Participants in the Composite Design Pattern
  • Component which declares the common interface for
    all classes in the composite implements default
    behavior common to all classes, as appropriate
    and (optionally) defines an interface for
    accessing a components parent in hierarchy.
  • Leave which defines a behavior for primitive
    objects.
  • Composite, which declares an interface for
    accessing and managing its child compoonents,
    defines behavior for components having children,
    stores child components, and implements
    child-related operations in the Component
    interface.
  • Client, which manipulates objects in the
    composition through the Component interface

20
Component operation() add(Component) remove(Compo
nent) getChild(int)
Client

Leaf Operation()
Composite operation() add(Component) remove(Compo
nent) getChild(int)
Write a Comment
User Comments (0)
About PowerShow.com