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.

11. MementoPrzeznaczenie (cytat z ksiki <strong>GoF</strong>):Nie naruszajc kapsułkowania zapamituje i udostepnia na zewntrz stan wewntrznyobiektu, tak e obiekt moe by poniej przywrócony do zapamitanego stanu.Przeznaczenie (cytat z fluffycat):Jeden obiekt przechowuje stan innego obiektu.Opis: Przykład ilustruje sposób wycofania si z niepoprawnego wzbogacenia wczeniejzapamitanego tytułu.Problem: JakRozwizanie: PrzezKlasa główna:_DP_B_<strong>GoF</strong>_Mementopackage pk.dydakt.to.dp.b.gof.memento;import java.util.ArrayList;public class _DP_B_<strong>GoF</strong>_Memento {public static void main(String[] args) {DvdDetails.DvdMemento dvdMementoCaretaker;//the CaretakerArrayList stars = new ArrayList();stars.add(new String("Guy Pearce"));DvdDetails dvdDetails =new DvdDetails("Memento", stars, '1');dvdMementoCaretaker = dvdDetails.createDvdMemento();System.out.println("as first instantiated");System.out.println(dvdDetails.formatDvdDetails());System.out.println("");dvdDetails.addStar("edskdzkvdfb");//oops - Cappuccino on the keyboard!System.out.println("after star added incorrectly");System.out.println(dvdDetails.formatDvdDetails());System.out.println("");System.out.println("the memento");System.out.println(dvdMementoCaretaker.showMemento());//show the memento}}System.out.println("");dvdDetails.setDvdMemento(dvdMementoCaretaker);//back off changesSystem.out.println("after DvdMemento state is restored to DvdDetails");System.out.println(dvdDetails.formatDvdDetails());Klasa wzorca:89

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

Saved successfully!

Ooh no, something went wrong!