12.07.2015 Views

Podsumowanie wzorców projektowych GoF

Podsumowanie wzorców projektowych GoF

Podsumowanie wzorców projektowych GoF

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

public void setDvdMemento(DvdMemento dvdMementoIn) {dvdMementoIn.getState();}//save current state of DvdDetails in a DvdMementopublic DvdMemento createDvdMemento() {DvdMemento mementoToReturn = new DvdMemento();mementoToReturn.setState();return mementoToReturn;}//an inner class for the mementoclass DvdMemento {private String mementoTitleName;private ArrayList mementoStars;private char mementoEncodingRegion;//sets DvdMementoData to DvdDetailspublic void setState() {//Because String are immutable we can just set// the DvdMemento Strings to = the DvdDetail Strings.mementoTitleName = getTitleName();mementoEncodingRegion = getEncodingRegion();//However, ArrayLists are not immutable,// so we need to instantiate a new ArrayList.mementoStars = new ArrayList(getStars());}//resets DvdDetails to DvdMementoDatapublic void getState() {setTitleName(mementoTitleName);setStars(mementoStars);setEncodingRegion(mementoEncodingRegion);}}}//only useful for testingpublic String showMemento() {return ("DVD: " + mementoTitleName +", starring: " + getStarsString(mementoStars) +", encoding region: " + mementoEncodingRegion);}Wyjcie na konsoli:as first instantiatedDVD: Memento, starring: Guy Pearce, encoding region: 1after star added incorrectlyDVD: Memento, starring: Guy Pearce, edskdzkvdfb, encoding region: 1the mementoDVD: Memento, starring: Guy Pearce, encoding region: 1after DvdMemento state is restored to DvdDetailsDVD: Memento, starring: Guy Pearce, encoding region: 191

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!