PHP5.0 object model deep exploration

Source: Internet
Author: User
Object-oriented programming is designed to provide solutions for large-scale software projects, especially projects with multi-person cooperation. when the source code is increased to 10 thousand lines or even more lines, every change may cause undesirable side effects. this situation occurs when modules are formed.

Object-oriented programming is designed to provide solutions for large-scale software projects, especially projects with multi-person cooperation. when the source code is increased to 10 thousand lines or even more lines, every change may cause undesirable side effects. this happens when modules form a secret alliance, just like Europe before the First World War.

// Haohappy note: the association between modules is too high, and the mutual dependence is too strong. a module must be changed as other modules change.

Imagine that a login processing module promised a credit card processing module to share its database connection. of course, the starting point is good, saving money for connecting to another database. however, sometimes the login processing module changes the name of one of the variables and may cut off the protocol between the two. this leads to an error in the processing of the credit card module, which leads to an error in the processing of the invoice module. soon, all irrelevant modules in the system may fail.

Therefore, I feel a little dramatic, and most programmers are grateful for coupling and encapsulation. coupling is a measure of the degree of attachment between two modules. the less coupling, the better. we hope that we can extract a module from an existing project and apply it to another new project.

We also hope to see a wide range of changes within a module without worrying about the impact on other modules. encapsulation principles can be provided to this solution plan. modules are regarded as relatively independent, and data communication between modules is performed through interfaces. modules do not use their variable names to gain a glimpse of another module. they use functions to send requests politely.

Encapsulation is a principle that you can apply in any programming language. in PHP and many process-oriented languages, it is very good to be lazy. there is nothing to prohibit you from using modules to build a hypothetical WEB. object-oriented programming is a method that prevents programmers from violating encapsulation principles.

In object-oriented programming, modules are organized into objects. these objects have methods and attributes. from an abstract point of view, a method is the action of an object, and a property is the feature of an object. from the programming point of view, the method is a function and the attribute is a variable. in an imaginary object-oriented system, each part is an object. the system consists of methods for connecting objects and objects.

A class defines the attributes of an object. if you are baking a set of cookies, the category will be a cookie machine. class attributes and methods are called members. people can express data members or method members.

Each language provides a different way to visit objects. PHP borrows concepts from C and provides a data type to include functions and variables under an identifier. When PHP was initially designed, or even when PHP3 was developed, PHP was not intended to provide large projects with more than 0.1 million lines of code. With the development of PHP and Zend engines, it is possible to develop large projects, but regardless of the scope of your project, writing your scripts using classes will allow code to be reused. 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 gratifying concepts in computer science. It is hard to grasp it at the beginning, but I can assure that once you grasp it, it will be very natural to think with it.

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.