From the course: Java Design Patterns: Behavioral Part 1
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Challenge: The Memento pattern - Java Tutorial
From the course: Java Design Patterns: Behavioral Part 1
Challenge: The Memento pattern
(upbeat music) - Let's have a look at the next exercise. And this one, we've got a simple calculator app. So if I open up this add a class, I can see that it has a field of type into called results. And it has two methods to add to the results. And to get the results. In the calculator class itself, I've got the main method where I'm creating an adder object, then I'm adding 10 and printing out the result. So if I run the app now, I can see it prints out the number 10 to the console. Under this, I've got some commented out code, where I'm adding 20, then I'm calling the Save method, then I'm printing the results, then I'm calling an undo method and printing the results again, this exercise is to implement those save and undo methods in the adder class, and you should implement them with the help of a momental class. The solution can be very similar to the momental pattern as I demonstrated in the previous video. When…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.