| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
To encapsulate invocation and decoupling.
We have an Invoker and a Receiver. This pattern uses a "Command" to delegate the method call against the Receiver and presents the same method "execute". Therefore, the Invoker just knows to call "execute" to process the Command of the client. The Receiver is decoupled from the Invoker.
The second aspect of this pattern is the undo(), which undoes the method execute(). Command can also be aggregated to combine more complex commands with minimum copy-paste and relying on composition over inheritance.
You can also find these code on GitHub
CommandInterface.php
.. literalinclude:: CommandInterface.php :language: php :linenos:
HelloCommand.php
.. literalinclude:: HelloCommand.php :language: php :linenos:
Receiver.php
.. literalinclude:: Receiver.php :language: php :linenos:
Invoker.php
.. literalinclude:: Invoker.php :language: php :linenos:
Tests/CommandTest.php
.. literalinclude:: Tests/CommandTest.php :language: php :linenos:
| Back | FazBrowse Home | New Git URL |