Do you know all the 25 php design patterns? The following code introduces the memorandum mode (Memento mode )? Php * memorandum mode is not broken... 25 php
Design ModeDo you all know? The following code is used to introduce
Memorandum mode (MementoMode)
_ State = $ state;} public function getState () {return $ this-> _ state;} class Caretaker {private $ _ memento = null; public function getMemento () {return $ this-> _ memento;} public function setMemento ($ memento) {$ this-> _ memento = $ memento;} class Originator {private $ _ state = null; public function getState () {return $ this-> _ state;} public function setState ($ state) {$ this-> _ state = $ state;} public function createMemento () {returnnewMemento ($ this-> _ state);} public function setMemento ($ memento) {$ this-> _ state = $ memento-> getState ();} public function display () {echo "state = ". $ this-> _ state."
";}}$ ObjOriginator = new Originator (); $ objOriginator-> setState (0); $ objOriginator-> display (); $ objCareTaker = new CareTaker (); $ objCareTaker-> setMemento ($ objOriginator-> createmento (); $ objOriginator-> setState (1); $ objOriginator-> display (); $ objOriginator-> setMemento ($ objCareTaker-> getMemento (); $ objOriginator-> display ();
Other related design patterns:
Memorandum mode (Memento mode)
Observer Mode (Observer mode)
Template Method mode)
Command mode)
Composite mode)
Enjoy the metadata mode (flyweight mode)
Strategy mode)
State mode)
Adapter mode)
Factory mode)
Prototype)
Appearance mode (facade mode)
Singleton mode)
Bridge Mode)
Decorator mode)
Abstract factory mode (abstract factory mode)
Builder mode (Builder mode)
Visitor mode (Visitor mode)
Interpreter mode (Interpreter mode)
Mediator mode)
Responsibility Chain mode (Chain Of Responsibility mode)
Proxy mode)
Iterator mode)
Data Access Object mode (DAO mode)
Delegation mode)
Permanent address:
Reprint at will ~ Please bring the tutorial URL ^