1 / 8

COP 3331 Object Oriented Analysis and Design Chapter 9 – Patterns

COP 3331 Object Oriented Analysis and Design Chapter 9 – Patterns. Jean Muhammad. Overview. State Design Pattern Factory Design Pattern. State Design Pattern. Category: Behavioral Design Pattern Intent: Allow an object to alter its behavior when its internal state changes.

cornelison
Download Presentation

COP 3331 Object Oriented Analysis and Design Chapter 9 – Patterns

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COP 3331 Object Oriented Analysis and DesignChapter 9 – Patterns Jean Muhammad Reference – Object Oriented Software Development Using Java - Jia

  2. Overview • State Design Pattern • Factory Design Pattern Reference – Object Oriented Software Development Using Java - Jia

  3. State Design Pattern • Category: Behavioral Design Pattern • Intent: Allow an object to alter its behavior when its internal state changes. • Also known as: Objects for states. • Applicability: Use this state when • an object’s behavior depends upon its state and it must change it’s behavior at run time, depending upon that state. • methods have large, multipart conditional statements that depend on the object’s state (ie switch statements). Reference – Object Oriented Software Development Using Java - Jia

  4. State Design Pattern • Participants in the State Design Pattern: • Context: Defines the current state by maintaining an instance of a ConcreteState. • State: Defines an interface for encapsulating the behavior associated with a particular state of the context. • ConcreteState: place where each class implements a behavior associated with a state of context. Reference – Object Oriented Software Development Using Java - Jia

  5. Context requested State handle state.handle() ConcreteStateA handle() ConcreteStateB handle() Reference – Object Oriented Software Development Using Java - Jia

  6. Factory Design Pattern • Category: Creational Design Pattern • Intent: To define an interface for creating an object but defer instantiation to the subclasses. • Also known as: Virtual constructor. • Applicability: Use this state when • a class cannot anticipate the class of objects it must create. • a class defers to it’s subclasses to specify the objects to create. Reference – Object Oriented Software Development Using Java - Jia

  7. Factory Design Pattern • Participants in the State Design Pattern: • Product: Defines the interface of the objects to be created. • ConcreteProduct: Implements the Product interface, and may provide default implementation. • Creator: Defines one or more factory method that create abstract products, that is, objects of type Product. • ConcreteCreator: Overrides the factory method to return an instance of a ConcreteProduct. The Factory design pattern involves a factory class whose sole responsibility is to create objects. Reference – Object Oriented Software Development Using Java - Jia

  8. Product Creator factoryMethod() anOperation() Product = factoryMethod() ConcreteCreator factoryMethod() ConcreteProduct Return new ConcreteProduct() Reference – Object Oriented Software Development Using Java - Jia

More Related