Published Jun 3, 2016

Command, Repository and Mediator Design Patterns

    Delve into the intricacies of Command, Repository, and Mediator design patterns, as Coding Blocks hosts discuss their practical applications in software design, the importance of loose coupling, and the benefits of diversifying programming skills and effective unit testing.
    Episode Highlights
    Coding Blocks logo

    Popular Clips

    Episode Highlights

    • Applications

      The Command pattern is a versatile design pattern that finds applications in various scenarios, such as GUIs, video games, and task management. Joe Zack explains how this pattern allows for the encapsulation of requests as objects, enabling flexibility in executing commands without knowing the specifics of the actions involved 1. This abstraction is particularly useful in environments like Windows, where right-clicking on a file triggers a series of command objects that execute specific tasks, such as backing up or unzipping files 1. Alan Underwood highlights the pattern's utility in Android apps, where shared features across apps are managed through command objects that execute context-specific actions 1.

      The command line doesn't know the specifics of your class, of your library, what you're doing. All it knows is, hey, I give this guy this word and I'm out, right?

      --- Joe Zack

      This pattern's ability to decouple the sender and receiver of a command makes it ideal for creating flexible and maintainable code structures.

         

      State & Undo

      The Command pattern also plays a crucial role in managing state and facilitating undo operations. Michael Outlaw points out that while the pattern encapsulates the information needed to perform actions, it doesn't inherently manage state, which is where the Memento pattern comes into play 2. The Memento pattern captures the state of an object, allowing for rollbacks and true undo functionality, unlike the Command pattern, which focuses on executing and reversing actions 2. Alan Underwood elaborates on how the Command pattern can be used to queue actions, enabling easy undo operations by simply reversing the sequence of commands 3.

      The command pattern doesn't have a state. An example with the photoshop thing with the memento is, you would say cut, copy, paste, whatever. It would actually keep a snapshot of the entire state.

      --- Joe Zack

      This distinction between managing actions and states highlights the complementary nature of the Command and Memento patterns in software design.

    Related Episodes