Wednesday, 5 February 2014

Command Design pattern - Class Diagram

Master Core Java Architecture & Design Patterns!

Subscribe to Ram N Java for clean code principles, GoF design patterns, and step-by-step software engineering tutorials!

🔔 Subscribe to Ram N Java

Structural Overview of the Command Pattern

The Command Design Pattern is a behavioral design pattern cataloged by the Gang of Four (GoF) that encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.

To understand how this decoupling is achieved in object-oriented systems, analyzing the UML Class Diagram is essential. It defines clear boundaries between the entity that triggers an action, the abstraction representing the action, and the component that performs the actual business operation.

Class Diagram Participants & Relationships

The UML structure of the Command pattern is composed of five central participants:

  • Command (Interface): Declares the abstract execution method, typically execute() (and optionally undo()).
  • ConcreteCommand: Implements the Command interface. It maintains a reference to the Receiver and defines the binding by calling the corresponding operation on the receiver when execute() is invoked.
  • Invoker: Holds a reference to a Command object (via composition or aggregation) and asks the command to carry out the request by calling its execute() method.
  • Receiver: Knows how to perform the operations associated with carrying out the request. Any class can serve as a receiver.
  • Client: Creates a ConcreteCommand object, binds it to a Receiver, and assigns it to an Invoker.

Architectural Benefits Reflected in the Diagram

The structural arrangement depicted in the class diagram provides critical design advantages:

  • Loose Coupling: The Invoker has no compile-time dependency on concrete receivers; it only interacts with the generic Command abstraction.
  • Open/Closed Principle: You can add new concrete command implementations without modifying existing invokers, receivers, or client code.
  • High Cohesion: Each command class encapsulates only the logic required to invoke a specific business action on its target receiver.

Related Tutorials from Ram N Java


Click here to watch in Youtube : https://www.youtube.com/watch?v=HWGfIqtqs8I

Click the below Image to Enlarge
Command Design pattern - Class Diagram


















See also:

  • Command Design pattern - Introduction
  • Command Design pattern - Real time example [Hotel]
  • Command Design pattern - Real time example [Menu]
  • Command Design pattern - Sequence Diagram
  • Command Design pattern - Object Creation and flow
  • Command Design pattern - Implementation [Menu]
  • Command Design pattern - Key points
  • All Design Patterns Links
  • No comments:

    Post a Comment

    Tutorials