Home > Article > Backend Development > PHP study notes - object-oriented (1)
1. First, let’s talk about what an object is (hereinafter we will use the object ‘someone’ to explain)
1) The object is unique, and the object is a specific thing in the objective world.
2) It can only complete specific functions.
3) Objects can be reused.
2. The object contains two parts:
1) The component elements of an object are the data model of the object, used to describe the purchase data, also known as the properties of the object, or the member variables of the object.
For example, someone: height, weight, etc. are all attributes of the object.
2) The behavior of an object is used to describe what the object can do, and is also called the method of the object (what we often call functions).
Someone’s behavior: eating, drinking, and sleeping.
3. What is object-oriented?
Object-oriented programming means that the data structure (data organization method) is stored through the structure of the object during programming. (properties, methods)
Why use object-oriented?
1) The description method of objects is more suitable for the real world and is conducive to the understanding of large-scale business.
2) When analyzing the world from the perspective of objects during the actual process of programming, it can shorten the distance between programming and the real world.
4. The essence of object-oriented
1) Object-oriented is to store all the problems to be solved in life in the form of objects (properties, methods)
2) Interaction between objects is completed through method calls
For example, a courier delivers goods to someone through the method of "delivery".
5. Basic ideas of object-oriented
The first step: identify the object
Any entity can be recognized as an object
Second step:
The data stored in the object is recognized as attributes
For different business logic, the data of concern is different, and the attributes stored in the object are also different
Step 3: Identify the object’s behavior
Changes to the object’s own attribute data
Objects and external interactions
6. Basic principles of object-oriented
The object is internally highly cohesive: the object is only responsible for one specific function (the function can be large or small). All object-related content is encapsulated inside the object.
Objects are low-coupled to the outside world: the outside world can see some properties of the object (but not all). For example, someone's privacy cannot be seen by the outside world.
The outside world can see that objects can do certain things (not all). For example, some things someone does cannot be seen by the outside world.
The above introduces the object-oriented (1) of PHP study notes, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.