Love Is Gone

This minimalist love which I am worn. “Love Is Gone” is published by Hunter Pratt in Poetrica.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Memento Design Pattern

Memento design pattern falls under the behavioural design patterns category. Mainly memento design pattern is used to restore state of an object to a previous state. Memento design pattern relies on three pillars they are,

· Originator: The object for which the state is to be saved. It creates the memento and uses it in future to undo.

· Memento: the object that is going to maintain the state of originator.

· Caretaker: the object that keeps track of multiple mementos.

· In this class, developer needs to implement List to hold components.

· The developer further needs to create a method which can add items to the List.

· Finally, the developer needs to create a getter method to get the List.

Note: We need to clone the ArrayList because if developer assigns an already existing array in to the new one, it will copy object reference that are contained in the ArrayList as result of that if developer manipulates one ArrayList’s object it will affect the other ArrayList, to eliminate this problem developer can use clone method.

In this class I use static Memento class as an inner class, but developer also can use a separate class.

· In this memento class developer needs to create an ArrayList without initializing.

· Also needs to create a constructor class accordingly.

· Finally needs to create getters for the ArrayList.

In this class we use stack data structure because when undoing we need to undo the most recent software component which means last in first out method.

Output:

Software{components=[Component{componentName=’Frontend Validation’}]}

Software{components=[Component{componentName=’Frontend Validation’}, Component{componentName=’WebSocket’}, Component{componentName=’Authenticator’}]}

Software{components=[Component{componentName=’Frontend Validation’}, Component{componentName=’WebSocket’}, Component{componentName=’Authenticator’}, Component{componentName=’Backend Validation’}, Component{componentName=’Business Function’}, Component{componentName=’Database Connection’}]}

Software{components=[Component{componentName=’Frontend Validation’}, Component{componentName=’WebSocket’}, Component{componentName=’Authenticator’}, Component{componentName=’Backend Validation’}, Component{componentName=’Business Function’}, Component{componentName=’Database Connection’}]}

Software{components=[Component{componentName=’Frontend Validation’}, Component{componentName=’WebSocket’}, Component{componentName=’Authenticator’}]}

Software{components=[Component{componentName=’Frontend Validation’}]}

Cannot revert, you have reach to the end…..

Software{components=[Component{componentName=’Frontend Validation’}]}

Note: Memento design pattern creates versions of a current status not just an instance.

You can see in the above output that same output is prompted twice. This happens because the last version that was stored in the caretaker and the version that you have are the same.

Easy recovery techniques are provided by this pattern.

The application will consume a huge amount of memory if the user creates many mementos.

I hope you are now able to understand what a memento design pattern is, how to implement the memento, and what are the advantages and disadvantages of it.

Add a comment

Related posts:

A lesson too hard to take

As a friend of flag once told me, always move where the wind takes you as long as you remain firmly attached to a rigid pole. Well, I have always had my doubts about my gambling habit, I have never…

Discussing the Social Dilemma

This past weekend I watched the Social Dilemma and thought about my own relationship with social media and how it defined my adolescence and self-perception. As someone who was chained to their phone…

What is Secret Email System?

Before I made the BMG10 Method — I was battling with my online business for quite a long time and was very nearly surrendering. I was working 60–80 hour weeks, pursuing and conversing with customers…