: 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.