PHP Object-Oriented programming

Source: Internet
Author: User

  1. Object-oriented programming (oriented Programming,oop) is a computer programming architecture, one of the basic principles of OOP is that a computer program is a single unit or object can play a role in the composition of the program, in order to achieve Zheng iron operation, Each object reads to receive information, process data, and send information to other objects. OOP achieves the three goals of software engineering: reusability, flexibility, and extensibility, making the code more concise, maintainable, and reusable. Object-oriented is a hot topic in the field of software development, first of all, object-oriented conforms to the general law of human beings ' view of things. Secondly, the object-oriented design method can make all parts of the system perform their duties and his ability. But PHP is not a true object-oriented language, but rather a hybrid language that can be programmed using object-oriented programming, or with traditional procedural processes. However, for large projects, you may need to use pure object-oriented thinking in PHP to design.

    Object-oriented programming is divided into two directions:

    Syntax for object-oriented technology

    The idea of object-oriented programming

    Relationships between classes and objects

    The relationship between a class and an object is like the relationship between a mold and a casting, and the instantiation of the class results in the object, and the object's abstraction is the class. Class describes a set of objects that have the same attributes and the same behavior. At development time, abstract classes are used to create objects, and objects are used directly in our programs instead of classes.

    What is a class

    In an object-oriented programming language, a class is a separate unit of program, a collection of objects that have the same properties and services. It provides a uniform abstract description of all objects that belong to the class, including the two main parts of the member properties and methods of the service.

    What is an object

    In the objective world, all things are made up of the connection between the object and the object. An object is an entity used to describe an objective thing in a system, which is a basic unit of a system, an object that consists of a set of attributes and a package of services that are authorized to operate on those properties.

  2. Specifically understand what a class is and what is an object

    One of the most prominent features of a class, or different from other classes, is what kind of requests you can make to it, which can do those things for you. For example, you go to Zhongguancun Electronics City want to buy a few PCs assembled, what is the first thing you should do? Is the installation of the engineer and you sit together, according to your needs and you to complete an installed configuration list. You can think of this configuration list as a class, or a custom type, it records the type of PC you want to buy, if you press this configuration to assemble 10 PCs, these 10 machines can be said to be the same type, can be said to be a class.

    So what is an object? The result of the instantiation of the class is the object, and the PC that is assembled by the configuration order of the PC is the object, which is the entity we can manipulate. Assemble 10 PCs, create 10 objects, each PC is independent, only to indicate that they are configured according to the same type, any action on one PC will not affect the other 9 machines. However, if the class is modified, that is, on the PC's configuration list with one or fewer accessories, then the assembled 10 machines are changed.

    Class is actually like our real World food classification, by car class, all cars belong to this class, for example, Mercedes-Benz, BMW is one of the car category, by the human, all people belong to this category, such as the Chinese, Americans, workers, students, etc. belong to one of mankind; there are balls, All the balls belong to this class, such as basketball, football, volleyball and so on. In the program design, we also need to classify some related variable definitions and function declarations into a custom type. This type allows you to create multiple entities, an entity that is an object, and each object has content attributes defined in that class.

    Object-Oriented Programming

    In the early PHP4, the object-oriented function is very imperfect, so the program designers almost adopt the process of modular programming, the basic unit of the program is composed of functions. The release of the PHP5 version marks the advent of a new PHP era, with its greatest feature being the introduction of all-object-oriented mechanisms and the retention of downward compatibility. Developers no longer have to write classes that lack functionality and can implement class protection in a number of ways. When designing a program, the program designer can use the object as the basic unit of the program.

    In object-oriented program design, it is difficult for beginners to understand the basic syntax used in object-oriented programming, but how to use object-oriented mode to design the program. For example, how many classes are used for a project? What classes are defined? When does each class create an object? Where can I use the object? The relationship between an object and an object, and how information is passed between objects.

    Suppose there is a project in which a university needs to build 5 multimedia classrooms, each of which can be used by 50 students. What should you do if you are given the project to complete? Do you need 5 rooms, 50 computer tables and 50 chairs in each room, and then buy 50 computers, 1 whiteboards and a projector? What are these? These entities that can be seen are objects, or they can be said to be the constituent units of these multimedia classrooms. Multimedia classrooms need to know everything, how to prepare it? It is necessary to classify all the things that need to be divided into room class, table type, chair class, Computer class, Whiteboard class and projector class. Then define the details of each category, for example, the room class needs to define its area, the number of tables, even if the number of chairs, and so on, according to this room class design can build 5 room objects as a classroom. The table class needs to define its length, width, height, and color, and all the tables that pass through the sound field of the table are the same type. Make a computer class that lists the detailed configuration of the computer you need so that you can purchase the computer that belongs to that type. And so on, each object can be prepared so that the objects that are created are placed in their classrooms, and then used by the student object to associate multiple objects together.

  3. 3

    The development of an object-oriented system program is similar to creating a multimedia classroom, in which each individual function module is abstracted into a class and instantiated into an object, which is then composed of multiple objects. The interaction between these objects, which can receive information, process data, and send information to other objects, constitutes an object-oriented program.

PHP Object-Oriented programming

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.