Object Oriented Programming (OOP) is a computer programming architecture. A basic principle of OOP is that a computer program is composed of a single unit or object that can function as a subroutine. OOP achieves the three goals of software engineering: reusability, flexibility, and scalability. In order to realize the overall operation, each object can receive information, process data and send information to other objects. Object-oriented has always been a hot topic in the field of software development. First of all, object-oriented is in line with the general rules of how humans look at things. Secondly, the use of object-oriented methods allows each part of the system to perform its duties and perform its duties. This opens the door for programmers to write code that is simpler, easier to maintain, and more reusable. Some people say that PHP is not a true object-oriented language, and this is true. PHP is a hybrid language, you can use OOP or traditional procedural programming. However, for large projects, you may need to use pure OOP to declare classes in PHP, and only use objects and classes in your project. I won’t go into detail about this concept, because the main reason why many friends stay away from object-oriented programming is that they can’t understand it when they come into contact with it, so they don’t want to learn it. Let the readers understand the concept after reading the entire content.
First video tutorial:
bkJia Video Tutorial 17: Learning PHP Object-Oriented Development (1)
bkJia Video Tutorial 18: Learning PHP Object-Oriented Development (2)
bkJia Video Tutorial 19: Learning PHP Object-Oriented Development (3)
bkJia Video Tutorial 20: Learning PHP Object-Oriented Development (4)
bkJia Video Tutorial 21: Learning PHP Object-Oriented Development (5)
bkJia Video Tutorial 22: Learning PHP Object-Oriented Development (6)
bkJia Video Tutorial 23: Learning PHP Object-Oriented Development (7)
bkJia Video Tutorial 24: Learning PHP Object-Oriented Development (8)
bkJia Video Tutorial 25: Learning PHP Object-Oriented Development (9)
Example:
bkJia Video Tutorial 26: Make your own PHP+MYSQL class
More related
============================================ ==============
Article directory:
1. Object-oriented concept
2. What is a class, what is an object, and the relationship between classes and objects
3. What is object-oriented programming?
4. How to abstract a class?
5. How to instantiate objects?
6. How to use members in the object?
7. The use of special reference "$this"
8.Construction method and destruction method
9. Encapsulation
10. Application of the four methods __set(), __get(), __isset() and __unset()
11. Class inheritance
12. Polymorphic applications
13. Overload new methods
14.Access type
15. Use of static members
16.Application of final keyword
17.__toString() method
18.Clone object
19.__call handles calling errors
20. Automatically load classes
21. Serialize objects
22. Abstract methods and abstract classes
23.php5 interface technology
============================================ ==============
2. What is a class, what is an object, and the relationship between classes and objects
The concept of class: A class is a collection of objects with the same properties and services. It provides a unified abstract description for all objects belonging to this class, which includes two main parts: properties and services. In object-oriented programming languages, a class is an independent program unit. It should have a class name and include two main parts: attribute description and service description.
The concept of object: An object is an entity used to describe objective things in the system. It is a basic unit that constitutes the system. An object consists of a set of properties and a set of services that operate on the set of properties. From a more abstract perspective, an object is an abstraction of something in the problem domain or implementation domain. It reflects the information that the thing needs to save and the role it plays in the system; it is a set of attributes and the right to control these attributes. An encapsulation of a set of services that perform operations. The objective world is composed of objects and the connections between objects. The relationship between classes and objects is like the relationship between molds and castings. The instantiation result of a class is an object, and the abstraction of a type of object is a class. A class describes a group of objects that have the same characteristics (properties) and the same behavior (methods). The above are probably their definitions. Maybe you are new to object-oriented. Don’t be confused by the concepts. Let me give you an example. If you go to Zhongguancun and want to buy a few assembled PCs, when you get there, you The first step is to have the installation engineer sit with you and complete an installation configuration sheet with you based on the information you provided. This configuration sheet can be imagined as a class, it is just a piece of paper, but It records the information of the PC you want to buy. If you use this configuration list to buy 10 machines, then these 10 machines are all composed according to this configuration list, so these 10 machines are of the same type, which can also be said It's the same type. So what is an object? The instantiation result of a class is an object. The machine configured (instantiated) using this configuration sheet is an object. It is an entity that we can operate. There are 10 machines and 10 objects. Each machine is independent, which only means that they are of the same type. Any action taken on one of the machines will not affect the other 9 machines. However, when I modify the class, I add one or less to this configuration list. If an accessory is used, all nine installed machines will be changed. This is a class-object relationship (the instantiation result of a class is an object).
3. What is object-oriented programming?
Not to mention his concept, if you want to build a computer classroom, you must first have a room with N computers, N tables, N chairs, whiteboards, projectors, etc. These are What, as we just said, these are objects, entities that can be seen. It can be said that the units of this computer classroom are these entity objects. They together make up this computer classroom. So we are doing programs, which What does it have to do with object-oriented? Developing a system program is similar to building a computer classroom. You abstract each independent functional module into a class and form an object. The system is composed of multiple objects. These objects can receive information, process data and send data to other objects. Information and so on interact. It constitutes an object-oriented program.
4. How to abstract a class?
As mentioned above, the unit of an object-oriented program is an object, but an object is instantiated by a class, so the first thing we have to do is how to declare a class. It is easy to make a class as long as you master the basic procedures. Grammar definition rules can be done, so what’s the difficulty? How many classes and objects should be used in a project, where the class should be defined, what kind of class is defined, how many objects are instantiated by this class, how many attributes are there in the class, how many methods are there, etc. This requires readers to analyze, design and summarize practical problems in actual development. Class definition:
class class name{
}
Use the keyword class followed by a class name you want and a pair of curly brackets. In this way, the structure of a class is defined. Just write the code in it, but what should be written in it? ? What can I write? How to write a complete
What about classes? As mentioned above, the purpose of using a class is to instantiate objects for us to use. This requires knowing what kind of object you want. Like the installation configuration sheet we mentioned above, what is written on the installation configuration sheet? The machine has everything. For example, a person is a target. How do you recommend a person you like to your leader? Of course, the more detailed the better: First, you will introduce the person's name, gender, age, height, weight, phone number, home address, etc. Then, you have to introduce what this person can do, whether he can drive, speak English, use a computer, etc. As long as you introduce more, others will know more about this person. This is our description of a person. Now let's summarize, all objects we use classes to describe are similar. As you can see from the description of the person above , to make a class, it is divided into two parts from the definition point of view. The first is a static description, and the second is a dynamic description. The static description is what we call attributes. As we saw above, people name, gender, age, height, weight, phone number, home address, etc. Dynamically speaking, it is the function of this human object. For example, this person can drive, speak English, use a computer, etc., abstracted into a process