1 / 8

Command Pattern

Command Pattern. Chihung Liao Cynthia Jiang. Order Execute(). Waiter. Hamburger Execute(). Hot Dogs Execute(). Fries Execute(). Cook Make Food(). Order Execute(). Abstract command (superclass). Hamburger Execute(). Hot Dog Execute(). Fries Execute(). Concrete command

olympe
Télécharger la présentation

Command Pattern

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. Command Pattern Chihung Liao Cynthia Jiang

  2. Order Execute() Waiter Hamburger Execute() Hot Dogs Execute() Fries Execute() Cook Make Food()

  3. Order Execute() Abstract command (superclass) Hamburger Execute() Hot Dog Execute() Fries Execute() Concrete command (subclass)

  4. Command Execute() Client Invoker Receiver Action() ConcreteCommand Execute() State

  5. Flexibility and Extensibility • Encapsulate a request as an object • Compare to C function pointer • Decouple the client and receiver by the invoker who ONLY invoke an operation • Any request can be cancelled or added in form of stack • Request to be executed can be stored as a queue

  6. Translate into JAVA 1 • Interface Command: an interface for executing an operation (it could also be an abstract class, refer to the sample code’s comment) • Class Client: creates a ConcreteCommand object and set its receiver • Class Receiver: who actually DOES things

  7. Translate into JAVA 2 • Class Invoker: ask Command to carry out an execution, an agent between ConcreteCommand and Client • Class ConcreteCommand implements Command: MUST have the method in Interface Command

  8. QUESTIONS

More Related