The memo mode of Java design mode

Source: Internet
Author: User

http://www.verejava.com/?id=16999143457673

Package Com.memento.theory;import Java.util.stack;public class testmemento{public static void Main (string[] args) {                Mementocontainer container=new Mementocontainer ();        Originator orig=new originator ();        Orig.setstate ("Summary");                Container.push (Orig.creatememento ());        Orig.setstate ("work Report");                Container.push (Orig.creatememento ());                Orig.setstate ("Happy New Year Job report");                Orig.show ();        Orig.setmemento (Container.back ());                Orig.show ();        Orig.setmemento (Container.back ());                Orig.show ();        Orig.setmemento (Container.forward ());                Orig.show ();        Orig.setmemento (Container.forward ());                    Orig.show ();    }}package Com.memento.theory;public class originator{private String state;    Public originator () {super ();    } public String GetState () {return state;        } public void SetState (String state) {This.state = State;    } public Memento Creatememento () {Return to New Memento (state);    } public void Setmemento (Memento Memento) {this.state = Memento.getstate ();    public void Show () {System.out.println (state);    }}package Com.memento.theory;public class memento{private String state;        Public Memento (String state) {super ();    This.state = State;    } public String GetState () {return state;    public void SetState (String state) {this.state = state; }}package com.memento.theory;import Java.util.arraylist;import java.util.list;import Java.util.Stack;public class    mementocontainer{private stack<memento> mementos;        private int index;    Public Mementocontainer () {mementos=new stack<memento> ();        } public void push (Memento Memento) {Mementos.push (Memento);    index++; } public Memento Forward () {MeMento memento= (Memento) mementos.get (index);        index++;    return memento;        } public Memento back () {index--;                Memento memento= (Memento) mementos.get (index);    return memento; }}

http://www.verejava.com/?id=16999143457673

The memo mode of Java design mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.