Memento Design Pattern

Поділитися
Вставка
  • Опубліковано 4 січ 2025

КОМЕНТАРІ • 111

  • @derekbanas
    @derekbanas  12 років тому +1

    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
    @derekbanas  12 років тому

    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?

    • @rajashekar543
      @rajashekar543 7 років тому

      Derek Banas sir please focus on j2ee

  • @kooboolc
    @kooboolc 11 років тому +18

    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 :)

  • @derekbanas
    @derekbanas  12 років тому

    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
    @derekbanas  11 років тому

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

  • @derekbanas
    @derekbanas  12 років тому

    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
    @derekbanas  12 років тому +3

    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

    • @leonard0104
      @leonard0104 3 роки тому

      have you done it?

    • @JackPurdon
      @JackPurdon 3 роки тому

      Lol you've 100% achieved that goal now hahaha

  • @derekbanas
    @derekbanas  12 років тому

    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.

  • @lauristamo3235
    @lauristamo3235 8 років тому +41

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

    • @ashrasmun1
      @ashrasmun1 7 років тому +7

      What's the problem then? Watch the part that is related to the pattern, then you can simply skip and that JElements stuff and watch how the program works :)

    • @nyarian835
      @nyarian835 7 років тому +6

      swing library is strongly connected with memento pattern.

    • @christopherrahme780
      @christopherrahme780 5 років тому +2

      The pattern is all there. You don't have to know how to use Swing, but using it is just a prettier way to visualize it.

    • @digitalalpha2
      @digitalalpha2 4 роки тому +1

      Tottaly agree, but then the video will be less than 10 min which is not profitable for the you-tuber

  • @derekbanas
    @derekbanas  12 років тому +3

    I want all of you guys to know I take your requests very seriously. I wouldn't have made a tutorial destined to never get views like Design Patterns if I didn't :) One thing I can't do though is bounce between tutorials. It is too hard for me to organize. If you all decide I should cover J2EE instead of games / Android I will. I'll have a vote very soon to make the final decision

  • @derekbanas
    @derekbanas  12 років тому

    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
    @derekbanas  12 років тому

    On the harddrive I would suppose. It just takes a few lines of code to store that information. Maybe I'm not understanding the question?

  • @amigoscode
    @amigoscode 11 років тому

    thanks. lk u know walmart self service checkouts??what did they use to create the GUI?

  • @derekbanas
    @derekbanas  12 років тому

    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
    @derekbanas  12 років тому

    Ich bin dankbar, dass Sie meine Videos sehen. Danke

  • @derekbanas
    @derekbanas  12 років тому

    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
    @derekbanas  11 років тому

    For GUI development I use Swing and the Standard Widget Toolkit

  • @derekbanas
    @derekbanas  12 років тому

    Are you trying to implement a layers system like Photoshop has?

  • @amigoscode
    @amigoscode 11 років тому

    is that the best API for GUI?

  • @derekbanas
    @derekbanas  12 років тому +1

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

  • @derekbanas
    @derekbanas  12 років тому

    Thank you very much :) There are ways to download the videos and a quick search will provide the answer

  • @derekbanas
    @derekbanas  12 років тому

    I'm sorry, but I can't do that. I had a lot of trouble when I allowed people to download them. I had a guy selling my videos. If you look into it, you can still find a way to download them. Why not watch them on UA-cam for free? I almost never even use preroll ads

  • @amigoscode
    @amigoscode 11 років тому

    lol I never been to Walmart.
    Why would u use C++ instead of Java Derek?

  • @derekbanas
    @derekbanas  12 років тому

    You never know when I'll upload a video :) I'll try to finish this tutorial tomorrow!
    Then UML 2.0 is next

  • @vevin1986
    @vevin1986 12 років тому

    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..

  • @wardenofthenorth-w5d
    @wardenofthenorth-w5d 4 роки тому +2

    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.

    • @Ferenc-Racz
      @Ferenc-Racz 3 роки тому +2

      Yes I thought for this exacty. To solve this problem you soud use a stack for redo also (or use index as in the example), and if any new momento was added to the history, then you should clear the redo stack (or delete every memento from the array after the index.)

  • @derekbanas
    @derekbanas  11 років тому

    Speed is the only reason. C++ is extremely fast in comparison to Java. I use C for hardware / electronics related projects.

  • @kennyPAGC
    @kennyPAGC 6 років тому +2

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

  • @tuongnguyen9391
    @tuongnguyen9391 2 роки тому

    Dear Mr Derek Banas,
    I still cannot understand this checking statement
    (saveFiles - 1) > currentArticle
    Q1: what if it just (saveFiles ) > currentArticle will anything happen catastrophically ?
    Q2: what is the relationship between saveFiles and currentArticle anyway ? Is this some type of two pointer techniqe ?

  • @123japanuser
    @123japanuser 12 років тому

    Yes Chief , webservices like SOAP / REST and Struts 2 would be Godsend.

  • @derekbanas
    @derekbanas  11 років тому

    You can pretty much watch them in any order.

  • @derekbanas
    @derekbanas  11 років тому

    You're very welcome :) Ill cover JavaFX ASAP.

  • @derekbanas
    @derekbanas  12 років тому

    In this tutorial I showed how to gray out components undoBut.setEnabled(false)

  • @karthikrangaraju9421
    @karthikrangaraju9421 10 років тому

    lovely presentation of Memento design pattern !

  • @TheDivergable
    @TheDivergable 12 років тому

    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

  • @KairmIhab88
    @KairmIhab88 12 років тому

    Thanks So much for the Video, and you really can make videos on any topics.
    Did u consider iOS & Objective -C videos
    I've started learning and you are the first that come to my mind.but I couldn't find any videos for you regarding iOS programming.

  • @TheDivergable
    @TheDivergable 12 років тому

    I got the font thing to work. Anyways I have a a question. If i have a JComponent class and I add it to my JFrame and I have another JComponent class and add it to the JFrame how could I make the one on the top transparent so everything I made in the first one would be still visible but if i had something in the second one it would be visible too?

  • @TheDivergable
    @TheDivergable 12 років тому

    Hmm, I'm not sure you understood me. This is what I meant.
    I have a class that extends JComponent and it has a method paint() obviously. I have painted some strings and shapes on it. I have added it to my JFrame. Now what I'm trying to do is add another class that extends JComponent and has a method paint obviously, and put it ontop of the other one I have, but when I do it overlays the other one. How could I fix it? If I put anything in it I still want it to show up though. Is this possible?

  • @TheDivergable
    @TheDivergable 12 років тому

    Nice tutorial.
    Quick question.
    You know games like Call of Duty etc. Any Games, how do they save the players profile and where would they save it?

  • @derekbanas
    @derekbanas  12 років тому

    That is terrible beyond words. I don't really know what to say. I just know that at times we seem to run out of options. There is such an amazing world out there though and so many things to see and do. For most of my life I've been lucky to see the amazing things and I just want to see more. The worst case scenario is that you have to live out in the woods all alone and live off of the land. Not so many years ago that is what most people did. My great grandparents did

  • @derekbanas
    @derekbanas  11 років тому

    I'm sorry, but I haven't been in Walmart for over 10 years. I have no idea what their checkout looks like. I'm guessing it was programmed in C++ because that is probably what I'd use.

  • @sirag1996
    @sirag1996 7 років тому +9

    Will Hello internet and welcome here if your lecturer can't explain this to you

  • @TheDivergable
    @TheDivergable 12 років тому

    Not exactly. I'm creating a game and I'm on the menu part and I have a JComponent class for the menu graphics where it draws the menu and I want a seperate JComponent class for the Dialogs. So what I'm trying to do is have my menu drawn by one class and then draw all my dialogs/confirm boxes drawn by another class and the dialog class is above the menu class and just displays all the dialogs

  • @OverG88
    @OverG88 12 років тому

    Spring and Hibernate after UML?

  • @TheDivergable
    @TheDivergable 12 років тому

    Could you show me how to import fonts into your program.
    This is what I've tried:
    Font font = null;
    try {
    graphicsEnvironment.registerFont(Font.createFont(Font.TRUE_TYPE_FONT, new File("./res/fonts/urban.ttf")));
    } catch(Exception e){ e.printStackTrace(); }
    font = new Font("Urban Sketch", Font.PLAIN, 30);
    when I used the graphicsEnv it showed my font but when i did g.drawString("test", 50, 50); it showed nothing but it normally did show the font and i also did do g.setFont(font);

  • @TheDivergable
    @TheDivergable 12 років тому

    sure, but you didnt show us how to add our own fonts. I looked it up and the code above is what i got and i impoerted the font but when i draw my string it will not show up when i have my font set to my custom font

  • @TheDivergable
    @TheDivergable 12 років тому

    Hmm, I'm thinking of how would they save it like minecraft worlds are saved in .dat files some games i'm not even sure they have external files for that. Just wondering how would you save a piece of info but not letting a user to simply change it

  • @tomyvarghese
    @tomyvarghese 11 років тому

    just getting into Design Patterns ..and i love your videos Derek !! ,although i am from an C# background
    ..in the Memento pattern example , noticed a lot of "if" statements, "if" statements usually point to a need for another design pattern (?)..usually..sometimes ...do correct the statement , i am kind of a newbie to Design Patterns

  • @derekbanas
    @derekbanas  12 років тому

    I am actually one of the people that talks to the Jehovah Witness when they come by. I'm always open to talk to anyone. I don't know very much about the religion though and have never attended any services there. I'm sorry if your experience there was so bad. That is a shame

  • @TheDivergable
    @TheDivergable 12 років тому

    Continuation of the last Comments...
    FYI I'm not talking bout the default java dialogs. I'm talking bout me drawing my own dialogs.

  • @tomyvarghese
    @tomyvarghese 11 років тому

    Thank you for clarifying Derek - i will check out the refactoring tutorials..

  • @derekbanas
    @derekbanas  12 років тому

    I thought I covered fonts previously? I'll have to go look back at my old tutorials

  • @shimonbalzera8618
    @shimonbalzera8618 7 років тому

    Clear and clean, THANK YOU VERY MUCH.

  • @kennyPAGC
    @kennyPAGC 6 років тому

    What if you want to save the state of multiple objects of multiple classes with multiple relations, instead of a simple class with a simple string attribute?

    • @hexrcs2641
      @hexrcs2641 6 років тому

      Use a dictionary or hashmap or things like that to store all the states in one place ;)

  • @herp_derpingson
    @herp_derpingson 12 років тому

    No matter what type of file you are trying to save, you basically have to put all the information into a string and write it into a hard drive.
    Say in minecraft probably the block id and location is saved and then the entire thing is compressed and encrypted. Then the unreadable string is saved with a ".dat" extension

  • @violetjellyfish2089
    @violetjellyfish2089 12 років тому

    Derek, ты супер!!! Твои видео просто невероятно полезны!!!

  • @TobiasFranke908
    @TobiasFranke908 7 років тому +2

    What is the purpose of the Memento class?
    It just stores a simple string. So why don't you use a String object and leave out the Memento class entirely?

    • @ashrasmun1
      @ashrasmun1 7 років тому

      It's just an example... A memento can be a way bigger and more complicated class. I bet it can be even abstracted out into a family of classes you would want to remember.

  • @matt-g-recovers
    @matt-g-recovers 5 років тому

    Thoughts going into the video...I used the state pattern for my current Android project and I realize just how much code duplication I have... I wonder if this will help

    • @derekbanas
      @derekbanas  5 років тому

      Happy I could help :) It is amazing how useful design patterns can be

  • @Ballistah
    @Ballistah 6 років тому

    Thank you! As always very understandable. But i am a little bit confused when I think about Memento and Command pattern. What is the difference in terms of undo/redo?

    • @hexrcs2641
      @hexrcs2641 6 років тому +1

      Memento is the true undo/redo - it stores the state of the originator, like snapshots. We can actually do time travels back or forth to any time if there's a snapshot available.
      Command's undo though is just a counter action of the last step, it can be useful when the states are deterministic and can be implemented with a state machine (see state pattern), eg. an ON-OFF switch and so on - the opposite of turnOn() is for sure turnOff(). If we have complex or infinite possible previous states, we will need to use true snapshots like Memento, eg. a String altered by a setter, we can't simply undo the changes if we don't know what exactly the counter action is.

  • @TheDivergable
    @TheDivergable 12 років тому

    im understanding all that and also there is going to be key navigation. But my main question is that thing i told you possible? If yes, how?

  • @packardjosy3881
    @packardjosy3881 8 років тому

    wow, what a voice, is it your real one, or do you use any kind of mic app ?
    by the way, thanks for the tutorial, I hate java and patterns, but I have to do some for my diploma, without you, I was so dead !

    • @derekbanas
      @derekbanas  8 років тому +1

      Thank you :) Yes that is my normal voice and no I don't edit it in any way

  • @ChrisVS
    @ChrisVS 9 років тому

    Hi Derek, as usual this is very useful and so well explained!!! I just noticed that when I tried to make it executable using your video "MAKE JAVA FILES EXECUTABLE" no 88 it won’t work... I also tried with few other exercises and it's the same unlucky result. Will you explain how to complete this please? Many thanks in advance and take care.

  • @wjrasmussen666
    @wjrasmussen666 10 років тому

    Very well done.
    Wondering, if this was a video game could it be used to save game state to a file?

    • @derekbanas
      @derekbanas  10 років тому

      Thank you :) Yes I tend to use patterns in general to help model out virtual worlds like games.

  • @FedJimSmith
    @FedJimSmith 11 років тому

    Wow thanks again Sir Derek. Please make some tutorials for JavaFX. I would like to learn GUI programming

  • @EricWTech
    @EricWTech 3 роки тому

    I don't see why using Editor and Snapshot (EditorState) classes are helpful. If we want to add or undo changes, then why not have a History class to store the state history in a Stack or a List? Why bring up other classes like Editor class or Snapshot class?
    public class History
    {
    private Stack states = new Stack();
    public void push(T item)
    {
    states.push();
    }
    public T pop()
    {
    return states.pop();
    }
    }

  • @2chikas
    @2chikas 11 років тому

    is one expected to follow these as presented here or you can watch in any order you like

  • @kiranMohantp
    @kiranMohantp 7 років тому

    this is simply awsome

  • @cacodailha
    @cacodailha 5 років тому

    Very nice!!!

  • @vevin1986
    @vevin1986 12 років тому

    I am looking Spring and Hibernate..Please do some tutorials if you find some free time ...Thanks in advance :)

  • @TheDivergable
    @TheDivergable 12 років тому

    when i said it normally did show the font i meant the text, it normally did show the text

  • @violetjellyfish2089
    @violetjellyfish2089 12 років тому

    You really can do any tutorial?! Maybe you can make tutorial about working with xml in java? :3

  • @SpiritsofCreativity
    @SpiritsofCreativity 12 років тому

    I am just all the tutorials quickly cause I am curious, but I think you should of done your java tutorials with this style, like the presentation thing at the begening

  • @ibnmrabetachraf5217
    @ibnmrabetachraf5217 9 років тому

    hey you re tuto are great, but can we get the source code pliize?

    • @derekbanas
      @derekbanas  9 років тому +1

      +ibn mrabet achraf Thank you :) Here is the source code www.newthinktank.com/2012/10/memento-design-pattern-tutorial/

  • @hussienfahmy7533
    @hussienfahmy7533 3 роки тому

    you are the best

    • @derekbanas
      @derekbanas  3 роки тому +1

      You are very kind :) I'm happy to help

  • @黄鹏程-z1r
    @黄鹏程-z1r 7 років тому

    I have to say that the all the swings stuff are reduntent...

  • @123japanuser
    @123japanuser 12 років тому

    Serienmäßig dankbar für diese Anstrengung. Mehr Leistung für Sie.
    Keine Medaille für mich wieder traurig.

  • @mykytaslywko779
    @mykytaslywko779 7 років тому

    awesome! :)

  • @OverG88
    @OverG88 12 років тому

    Well....I vote for Java EE! :)

  • @OverG88
    @OverG88 12 років тому

    ....because I watch this so late. :)

  • @Eskew251
    @Eskew251 12 років тому

    J2EE would be awesome.

  • @gabrielaudette7345
    @gabrielaudette7345 5 років тому

    use stack

  • @tellvivk
    @tellvivk 6 років тому

    coool example

  • @socerboy06
    @socerboy06 4 роки тому

    My hair is getting fewer...

  • @ukranaut
    @ukranaut 2 роки тому

    Not the best example.

  • @amirhosseinghorbani834
    @amirhosseinghorbani834 2 роки тому

    1 minute for memento, 19 minutes for java stuff, really?

    • @KublaiKhan2025
      @KublaiKhan2025 7 місяців тому

      Well, you don't need mode. This one is pretty simple, it just saves an object. And you can even use an array, to save different versions of the object.

    • @amirhosseinghorbani834
      @amirhosseinghorbani834 7 місяців тому

      @@KublaiKhan2025 you probably replied to a wrong comment!