Php design mode command (command mode)

Source: Internet
Author: User
Do you know all the 25 php design patterns? The following code introduces the command mode (command mode )? Php * command mode to send a request...

25 php typesDesign ModeDo you all know? The following code is used to introduceCommand mode(CommandMode)

 _ Command [] = $ command;} public function executeCommand () {foreach ($ this-> _ command as $ command) {$ command-> execute ();}} public function removeCommand ($ command) {$ key = array_search ($ command, $ this-> _ command); if ($ key! = False) {unset ($ this-> _ command [$ key]) ;}} class extends er {private $ _ name = null; public function _ construct ($ name) {$ this-> _ name = $ name;} public function action () {echo $ this-> _ name. "action
";} Public function action1 () {echo $ this-> _ name." action1
";}} Class ConcreteCommand implements Command {private $ _ javaser; public function _ construct ($ javaser) {$ this-> _ javaser = $ javaser;} public function execute () {$ this-> _ aggreger-> action () ;}} class ConcreteCommand1 implements Command {private $ _ aggreger; public function _ construct ($ aggreger) {$ this-> _ cycler = $ cycler;} public function execute () {$ this-> _ Cycler-> action1 ();}} class ConcreteCommand2 implements Command {private $ _ cmder; public function _ construct ($ cmder) {$ this-> _ cmder = $ cmder;} public function execute () {$ this-> _ receiver er-> action (); $ this-> _ receiver er-> action1 () ;}$ objRecevier = new Receiver er ("No.1 "); $ objRecevier1 = new Receiver er ("No. 2"); $ objRecevier2 = new Receiver er ("No. 3"); $ objCommand = new ConcreteCommand ($ objRecevier ); $ objCommand1 = new ConcreteCommand1 ($ response); $ objCommand2 = new ConcreteCommand ($ response); $ objCommand3 = new ConcreteCommand1 ($ response); $ objCommand4 = new ConcreteCommand2 ($ response ); // use the Recevier method $ objInvoker = new Invoker (); $ objInvoker-> setCommand ($ objCommand); $ objInvoker-> setCommand ($ objCommand1 ); $ objInvoker-> executeCommand (); $ objInvoker-> removeCommand ($ objCommand1); $ objInvoker-> executeCommand (); $ objInvoker-> setCommand ($ objCommand2 ); $ objInvoker-> setCommand ($ objCommand3); $ objInvoker-> setCommand ($ objCommand4); $ objInvoker-> executeCommand ();


Other related design patterns:

Http://www.phprm.com/develop/memento.html memorandum mode (Memento mode)
Http://www.phprm.com/develop/observer.html Observer mode (Observer mode)
Template Method pattern (Template Method pattern)
Http://www.phprm.com/develop/command.html command mode)
Http://www.phprm.com/develop/composite.html combination mode (composite mode)
Http://www.phprm.com/develop/flyweight.html enjoy mode (flyweight mode)
Http://www.phprm.com/develop/strategy.html strategy mode)
Http://www.phprm.com/develop/state.html state mode)
Http://www.phprm.com/develop/adapter.html adapter mode (adapter mode)
Http://www.phprm.com/develop/factory.html factory mode (factory mode)
Http://www.phprm.com/develop/prototype.html prototype)
Http://www.phprm.com/develop/facade.html appearance mode (facade mode)
Http://www.phprm.com/develop/singleton.html singleton mode)
Http://www.phprm.com/develop/bridge.html bridge Mode (bridge mode)
Http://www.phprm.com/develop/decorator.html decoration mode (decorator mode)
Http://www.phprm.com/develop/abstract.html abstract factory mode (abstract factory mode)
Http://www.phprm.com/develop/builder.html Builder mode)
Http://www.phprm.com/develop/visitor.html Visitor mode (Visitor mode)
Http://www.phprm.com/develop/interpreter.html Interpreter mode (Interpreter mode)
Http://www.phprm.com/develop/mediator.html Mediator mode)
Http://www.phprm.com/develop/chain.html Responsibility Chain model (Chain Of Responsibility model)
Http://www.phprm.com/develop/proxy.html Proxy mode)
Http://www.phprm.com/develop/interator.html iterator mode)
Http://www.phprm.com/develop/dao.html Data Access Object mode (DAO mode)
Http://www.phprm.com/develop/delegation.html delegate mode (Delegation mode)

Article: http://www.phprm.com/develop/command.html

Save this article for favorites!

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.