Php design mode Memento (Memorandum mode)

Source: Internet
Author: User
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 ^

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.