Section 1-Object-oriented programming-ClassesandObjectsinPHP51_PHP tutorial

Source: Internet
Author: User
Section 1-Object-oriented programming-ClassesandObjectsinPHP51. | This document is read by Haohappy. | notes in chapter ClassesandObjects in | translation-oriented + personal experience | to avoid unnecessary troubles, do not repost them, thank you | welcome to criticism | = This article is Haohappy read < > | = Notes in the middle Classes and Objects chapter | = Translation + personal experience | = do not repost to avoid unnecessary troubles, thank you | = Welcome to criticize and correct, hope to make progress together with all PHP enthusiasts! + ------------------------------------------------------------------- + */Section 1-object-oriented programming is designed to provide solutions for large software projects, especially projects jointly developed by many people. when the source code grows to 10 thousand lines or even more lines, every change may lead to unwanted side effects. this happens when modules form a secret alliance, just like Europe before the First World War. // haohappy note: the correlation between modules is too high, and the mutual dependence is too strong. when a module is updated, other modules must also be updated. imagine if a login processing module allows 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, when the login processing module changes the name of a variable, the protocol between the two may be broken. 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 Error. therefore, I think it is a little dramatic that most programmers are grateful for coupling and encapsulation. coupling is a measure of the degree of dependency between two modules. the less coupling, the better. we hope to extract a module from an existing project and use it in another new project. we also hope to make large-scale changes within a module without worrying about the impact on other modules. the encapsulation principle can provide this solution. modules are regarded as relatively independent, and data communication between modules is performed through interfaces. modules do not use their variable names to snoop on another module. they use functions to send requests politely. encapsulation is a principle that you can use in any programming language. in PHP and many process-oriented languages, it is tempting to be lazy. nothing can prevent 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 an action of an object, and a property is a feature of an object. from the programming point of view, the method is a function and the attribute is a variable. In an idealized object-oriented system, each part is an object. the system consists of links between objects and objects through methods. A class defines the attributes of an object. if you are baking a set of cookies, the class will be a cookie machine. class attributes and methods are called members. people can express data members or method members. each language provides different ways to access objects. PHP borrows the concept from C ++ and provides a data type to include functions and variables under an identifier. When PHP was initially designed and even when PHP3 was developed, PHP was not intended to provide the ability to develop large projects with over 0.1 million lines of code. With the development of PHP and Zend engines, it is possible to develop large projects. However, no matter how large your project is, 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 about objects is one of the most exciting concepts in computer science. It is hard to grasp it at first, but I can assure that once you master it, it will be very natural to think with it.

Http://www.bkjia.com/PHPjc/532168.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/532168.htmlTechArticle | = This article is Haohappy read> | = in the Classes and Objects chapter notes | = Translation + personal experience | = to avoid possible unnecessary trouble do not reprint, thank you | = welcome criticism...

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.