: This article mainly introduces (6) The second principle of object-oriented design. if you are interested in PHP tutorials, please refer to it. I. INTRODUCTION:
Command mode: the command mode can be divided into "the requester of the command" and "The real-time user of the command ". This decouples the request and implementation of commands.
II. example:
Cook = $ cook;} public function execute () {$ this-> cook-> meal () ;}} class DrinkCommand implements Command {private $ cook; public function _ construct (cook $ cook) {$ this-> cook = $ cook;} public function execute () {$ this-> cook-> drink ();}} /** simulation class */class cookControl {private $ mealCommand; private $ drinkCommand; public function addCommand (Command $ mealCommand, Command $ drinkCommand) {$ this-> mealCommand = $ mealCommand; $ this-> drinkCommand = $ drinkCommand;} public function callMeal () {$ this-> mealCommand-> execute ();} public function callDrink () {$ this-> drinkCommand-> execute () ;}}$ control = new cookControl (); $ cook = new cook; $ mealCommand = new MealCommand ($ cook ); $ drinkCommand = new DrinkCommand ($ cook); $ control-> addCommand ($ mealCommand, $ drinkCommand); $ control-> callMeal (); $ control-> callDrink ();
III. usage principles:
1. refine the business process according to the business process. Abstract step by step until 'right '.
2. pay attention to the classification of duties.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above section introduces (6) The second principle of object-oriented design, including some content. I hope my friends who are interested in PHP tutorials will be helpful.