Memento Design Pattern

preview_player
Показать описание

Welcome to my Memento Design Pattern Tutorial! The Memento design pattern provides a way to store previous states of an Object easily.

It has 3 main classes:

1. Memento: The basic object that is stored in different states. 

2. Originator: Sets and Gets values from the currently targeted Memento. Creates new Mementos and assigns current values to them. 

3. Caretaker: Holds an ArrayList that contains all previous versions of the Memento. It can store and retrieve stored Mementos.

All of the code is above to help you learn.
Рекомендации по теме
Комментарии
Автор

Love your videos.
I think that You shouldn't fuzz design pattern with Swing components though. It makes pattern harder to understand. Leave it for java specific tutorials :)

kooboolc
Автор

Why ? why all these swings and JElements ? :( I just try to understand pattern :|

lauristamo
Автор

I'm surprised that is of interest. If I cover the topic I'll start at the bottom with JSP and work my way up to cover everything. I'm getting good at posting regularly again and so should be able to blast through this topic. I'll hold a vote soon

derekbanas
Автор

I did that already :) Look at Java Video Tutorial 44, 45 and 46

If I had more time to make videos, I think I could cover any subject. I've spent my whole life learning new topics so it is fun for me. Maybe some day I'll be able to turn this hobby into a job

derekbanas
Автор

Yes you are correct. I cover how to eliminate the if statements in the refactoring tutorials

derekbanas
Автор

For GUI development I use Swing and the Standard Widget Toolkit

derekbanas
Автор

I don't know? I have kind of promised to cover OpenGL and Android games. People didn't seem to be too interested in my last game tutorial though. I think people don't understand the math and just give up? I'll be making that decision soon. UML will be followed by refactoring because nobody covers it and it is a perfect bind between design patterns and UML. They'll be pretty quick. Maybe I'll hold another vote after that?

derekbanas
Автор

I see where you are coming from. I used to think a lot about political problems. I guess I lost heart? I have never been very political. I prefer to help people in ways that I know we all can. I teach poor kids for free. I give food to food banks. I can list a bunch of things each and every person could do tomorrow and make a positive impact. I'm sure you can as well. I think a story must be written to break through the barriers in peoples minds. I'm not up to manipulate people now though

derekbanas
Автор

Ich bin dankbar, dass Sie meine Videos sehen. Danke

derekbanas
Автор

Thank you :) I did make an objective c tutorial years ago, but I was forced to take part of it down because I made a game that was out there already. I'm making android videos next and it will be a very long tutorial

derekbanas
Автор

I don't mean anything you said sounds like manipulation, I mean I think that is the only way to cut through manipulation that has forced them to turn a blind eye from reality. Look at the Ayn Rand books as an example. They convinced people through story telling to create a political movement beyond anything she probably could have ever imagined. Through stories you can convince people. People are blind to facts and arguing. You can only sneak in and persuade them through storytelling often

derekbanas
Автор

You could encrypt the information easily. There are numerous obfuscation techniques that you could use that would make the data very hard to change. You would have to save it some place though for later use.

derekbanas
Автор

Yes Derek, I really appreciate your dedication towards the online community..I understand that it will be very difficult for you to manage it, if you go by request of every individual.. :).. voting out is definitely a good option :).. I will benefit everyone :)
Thanks once again ..
God Bless You..

vevin
Автор

This sounds like something that would just be handled by painting what looks like components in a paint window. Then you'll have to simulate button clicking or whatever by capturing where the user clicks. You'll have to throw your own exceptions for those mouse clicks to react to the user

derekbanas
Автор

I don't know about subclassing another JComponent. I think I'd just paint everything from scratch. That way you can make it look however you want. If you use JComponents to much they will look completely different on every machine. I'm planning on covering Java 2D maybe depending on how voting goes next week.

derekbanas
Автор

for example I have a text area in my JFrame and when i press save then the text in the text area is saved somewhere but, I dont want a user to just be able to change that text by opening a file it was saved in. or could this even be done without the need of files? so you still have that info when you restart the program

TheDivergable
Автор

lovely presentation of Memento design pattern ! 

karthikrangaraju
Автор

Спасибо. Я очень рада, что вам понравилось :)

derekbanas
Автор

1, 2, 3, 4
undo, undo -> 2
add 5, what user sees -> 1, 2, 5, there is no redo because you are at the newest
but in your code, add 5 -> 1, 2, 3, 4, 5, redo get you 3
I think it's the design problem, maybe there should be a stack in which you delete / undo, and another list, they are synced when you add more nodes.

wardenofthenorth-wd
Автор

I find it weird that the restoreMemento method would return an attribute instead of an Originator object (with the updated attribute)

kennyPAGC