(7) third principle of object-oriented design

Source: Internet
Author: User
: This article mainly introduces (7) The third principle of object-oriented design. if you are interested in PHP tutorials, please refer to it. I. principles of openness and closure:
The basic idea is:
1. Open: The module behavior must be Open and support expansion, rather than being difficult to change.
2. Closed: when extending the functions of a module, it should not affect or greatly affect the original program module.

II. example:

 Message = $ event-> click (); if ($ this-> message instanceof process) {$ this-> message-> process ();}}} // player event Processing class mp4 {public function work () {$ playProcess = new playProcess (); $ playProcess-> callBack (new event ('encoding ')); $ playProcess-> callBack (new event ('output') ;}// event processing class event {private $ m; public function _ construct ($ me) {$ this-> m = $ me;} public function click () {switch ($ this-> m) {case 'encode': return new playerEncode (); break; case 'output': return new playerOutput (); break ;}}$ mp4 = new mp4 (); $ mp4-> work ();
III. others:

1. fully apply the "abstraction" and "encapsulation" ideas in design.
A. find a variable to encapsulate it.
B. variable factors of "same" should be encapsulated into the "same" object.
2. apply interface-oriented programming to system function programming implementation.
A. new classes can be provided to adapt to changes when requirements change.
B. functional interfaces are required for interfaces. the object declaration is of the interface type.

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 (7) The third 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.