Object-oriented php_php tutorial

Source: Internet
Author: User
Many languages are object-oriented, and it takes PHP a few years to introduce such features. Many people believe that previous attempts to add object-oriented functionality to the language have failed. Although version 4 provides a very basic object-oriented programming (OOP) concept, there are some shortcomings, including: • Informal method of object reference · You cannot set the scope of fields and methods (public, private, protected, abstract). No named constructors and standard conventions · Missing destructor for object. The object replication attribute is missing. Lack of support for interfaces. Fortunately, PHP5 eliminated all of these shortcomings, made an essential improvement to the original implementation, and added many new OOP features. The benefits of OOP the emergence of object-oriented programming is a major change in the development paradigm, with programmatic attention returning from the logic of the application to its data, in other words, OOP shifts focus from programmatic procedural events to the real body of the final model. This allows applications to be closer to the real world around us. Encapsulation programmers generally have a strong curiosity, and we like to take things apart and see how all the small parts inside work together. While it is possible to be spiritually satisfied, it is not necessary to have an in-depth understanding of the internal workings of things, for example, millions of people use computers every day, but few people really understand how it works, as well as cars, televisions and many commonplace things, and can ignore their internal structures by using interfaces. For example, you know that rotating the radio knob can be changed, but you may not know that this is actually telling the radio to listen to a signal that is transmitted using a specific frequency, which is done through the demodulator, even if it does not understand the process, and does not affect the use of the radio, because the interface hides these details, This method is known as encapsulation by separating the user from the internal workings of the actual application through well-known interfaces. Object-oriented programming enables the concept of the internal workings of hidden applications to be further enhanced by establishing well-defined (well-defined) interfaces that each application's components can access. A developer with OOP thinking will not fall into a lot of detail, but will design a component that is independent of the other components that are tightly bound or coupled (couple) well-defined interfaces to be called objects (object). Objects are created from a template called a class, which defines the data and behavior that an entity should have, which has the following advantages: • Developers can modify the application's implementation without affecting the object user, because the user interacts with the object only through the interface of the object. Can reduce user errors that may occur because of the control over the user's interaction with the application. Inheritance www.2cto.com in the environment around us, many things (including people) can be modeled using a well-defined set of rules. We look at the concept of employees, and all employees have a common set ofsuch as: Name, employee number, salary. However, there are many types of employees who do not scold, such as staff, supervisors, cashiers and CEOs. Each type of employee has a superset of the nature defined in the general employee definition. In terms of object-oriented terminology, these employee types inherit (inherit) the general employee definition, including all the properties and behaviors in this definition, and next, each particular employee class can also be inherited by another more explicit class, for example: "Clerk" type can be inherited by day shift staff and night staff, Day and night staff inherit all the attributes of the employee definition and staff definition. Based on this concept, you can then create a "people" class that makes the employee Class A subclass of the "People" class, and as a result, the employee class and all of its derived classes (employees, cashiers, CEOs, and so on) immediately inherit all the properties and behaviors defined in the "People" class. The object-oriented development approach is based on the concept of inheritance, which improves the reusability of code because it enables people to use well-designed classes in multiple applications [so-called well-designed (well-designed), meaning that these classes are abstract enough to be reused]. Polymorphic polymorphism (polymorphism) is a term derived from the Greek language and is intended to be "in many forms". In short, polymorphism refers to the ability of OOP to redefine or change the nature or behavior of a class based on the context in which it is used. As an example, it is assumed that there is a "check-in" and behavior in the definition of an employee class, which may be specific to the employee's staff, for example, for employees of its type, such as "programmer" sign-in may be over the network, although two classes inherit from the employee class to this behavior, But the specific implementation depends on the implementation of the "check-in" context, which is the powerful polymorphism of this place

http://www.bkjia.com/PHPjc/477844.html www.bkjia.com true http://www.bkjia.com/PHPjc/477844.html techarticle Many languages are object-oriented, and it takes PHP a few years to introduce such features. Many people believe that previous attempts to add object-oriented functionality to the language have failed. Do ...

  • Related Article

    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.