PHP5 Object Model [1] - Object-oriented programming

zhaozj2021-02-16  133

Section 1 - Object-oriented programming object-oriented programming is designed to provide solutions for large software projects, especially multi-person cooperation. When the source code grows to 10,000 lines or even more, each more It causes undesirable side effects. This situation occurs when the module forms a secret alliance, just like the first World War, Europe .//haohappy Note: The relationship between the module is high, the interdependence is too Strong. A module causing other modules to be forth. Imagine, if there is a module to process login to allow a credit card processing module to share its database connection. Of course, the starting point is good, save another The expenditure of the database connection. However, sometimes the login processing module changes the name of one of the variables, it may cut off the agreement between the two. Causes the handling of the credit card module, thereby causing the module that processes the invoice error. Soon, the system All unrelated modules may be wrong. So I think it is a bit dramatic. Most of the programmers are grateful to coupling and packaging. Coupled is a measure of two modular dependence. The less coupling is, better. We I hope to take a module from an existing project and use it in another new project. We also hope that there is a large scale in a module without worrying about the impact on other modules. The principle of packaging can provide this solution. Solution. The module is viewed to be relatively independent, and the data communication between the modules is performed by an interface. The module does not spy another module through the variable names of each other, and they pass the function to politely send a request. Package is you can in any programming language A principle used in the use of PHP and many process-oriented languages, it is very tempting. Nothing can stop you from building a virtual web. Object-oriented programming is not to violate the package principle One way. In object-oriented programming, the module is organized into an object. These objects have methods and properties. From an abstract perspective, the method is the action of an object, and the attribute is the object of the object. From a programming perspective, the method is the function and the attribute is a variable. In an ideal-oriented object system, each part is an object. The system is formed by the object and the object through the method. A class definition The properties of the object. If you are bake a set of sweet cake objects, the class will be a sweet cake machine. The class's properties and methods are members called. People can expressed by saying data members or method members. Language provides different ways to access objects. PHP borrows concepts from C , providing a data type to include functions and variables under an identifier. When I originally designed PHP, even PHP3 was developed, PHP did not intend to provide the ability to develop large projects that exceed 100,000 lines of code. With the development of PHP and Zend Engine, it is possible to develop large projects, but no matter how much your project is large, write your script with classes to make the code reuse. This is a good idea, especially when you are willing to share your code with others. The idea of ​​objects is one of the most exciting concepts of computer science. It is difficult to master it, but I can guarantee that once you have mastered it, it will be very nature.

转载请注明原文地址:https://www.9cbs.com/read-8150.html

New Post(0)