mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-19 07:26:31 +00:00
added memento sample
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.iluwatar;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
Stack<StarMemento> states = new Stack<>();
|
||||
|
||||
Star star = new Star(StarType.SUN, 10000000, 500000);
|
||||
System.out.println(star);
|
||||
states.add(star.getMemento());
|
||||
star.timePasses();
|
||||
System.out.println(star);
|
||||
states.add(star.getMemento());
|
||||
star.timePasses();
|
||||
System.out.println(star);
|
||||
states.add(star.getMemento());
|
||||
star.timePasses();
|
||||
System.out.println(star);
|
||||
states.add(star.getMemento());
|
||||
star.timePasses();
|
||||
System.out.println(star);
|
||||
while (states.size() > 0) {
|
||||
star.setMemento(states.pop());
|
||||
System.out.println(star);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user