(vi) Object-oriented design principles of the second

Source: Internet
Author: User
A Brief introduction:
Command mode: The command pattern is divided into "requestor of the Command" and "Implementation of the Command". Make the request for the command and the implementation complete understanding decoupling.

Two 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 ($co OK); $control->addcommand ($mealCommand, $drinkCommand); $control->callmeal (); $control->calldrink ();

Three Principle of Use:

1. Refine the business process according to the business process. Step-by-step abstraction until ' appropriate '.
2. The classification of responsibilities requires attention.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the (vi) object-oriented design principles of the second, including the aspects of the content, I hope to be interested in the PHP tutorial friends 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.