(6) object-oriented design principle 2

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

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.