Essential Java Design Patterns: Implementation Examples
Classified in Computers
Written on in
English with a size of 2.99 KB
Memento Pattern
The Memento pattern allows you to capture and externalize an object's internal state so that the object can be restored to this state later.
public class MementoDemo {
public static void main(String[] args) {
Caretaker caretaker = new Caretaker();
Originator originator = new Originator();
originator.setState("State1");
caretaker.addMemento(originator.save());
originator.restore(caretaker.getMemento());
}
}Composite Pattern
The Composite pattern is used to compose objects into tree structures to represent part-whole hierarchies.
public class CompositeDemo {
public static void main(String[] args) {
Box root = initialize();
int[] levels = new int[args.length];... Continue reading "Essential Java Design Patterns: Implementation Examples" »