Published Jul 26, 2015

Design Patterns Part 4 - Adapter, Facade, and Memento

    Explore the intricacies of software design with deep dives into the Adapter, Facade, and Memento patterns, as well as a lively debate on learning frameworks versus core languages, featuring insights from Alan Underwood, Michael Outlaw, and Joe Zack.
    Episode Highlights
    Coding Blocks logo

    Popular Clips

    Episode Highlights

    • Memento Pattern

      The memento pattern is a design pattern that allows for the rollback of an object's state to a previous point in time. Joe Zack explains that it involves taking a full snapshot of an object's internal state, enabling restoration if needed 1. This pattern is particularly useful in scenarios like database transactions, where a rollback might be necessary if an operation fails 2. However, it is not suitable for situations requiring frequent state changes, such as undo operations in text editors, due to its heavy memory usage 1.

      The memento pattern is very dumb. It just takes, like, basically a dehydrated object takes a copy, a picture of your object, and if things go south, it can restore it.

      --- Joe Zack

      Alan Underwood notes that while the pattern is not efficient, it is a brute force method to revert to a previous state 2.

         

      Implementation

      Implementing the memento pattern involves several challenges, particularly in managing the object's state. Joe Zack highlights that the pattern requires the object to save and restore its internal state, which can violate the single responsibility principle 3. The pattern involves three key components: the originator, the memento, and the caretaker, each playing a role in managing the state 4.

      The originator is the real object, the memento is the internal state, and the caretaker is the class in charge of rolling back.

      --- Joe Zack

      Michael Outlaw adds that while the pattern is conceptually simple, its implementation can become complex, especially when dealing with large objects or systems 3.

    Related Episodes