11-object-oriented basics, 11-object-oriented
Object-oriented Basics
First, let's give an example where I asked James to help me buy cigarettes:
Method 1:
1. I said to James, "Go down to the street and buy me a pack of cigarettes ."
2. You must first stand up and then turn right to the backdoor
3. If the door does not close, you can go out directly. If the door is closed, you need to open it and then go out again.
4. Turn right after going out and enter the stairs
5. If there are many people going up or down the stairs, you need to go right.
6. Then, on the road, if you see an old lady in need to help her
7. Then buy cigarettes
8. Check whether the change is true. If it is, return it.
......
Method 2:
1. I told James to buy me a pack of cigarettes.
2. James bought the cigarette and handed it to me.
We can see that in the two methods that let James buy cigarettes, the first method should be taken into account in the process of buying cigarettes, and the second method is to find a person to do things.
Therefore, the first method is process-oriented, and the second method is object-oriented.
The so-called process-oriented approach is to write code from top to bottom based on the business logic.
Object-oriented means to bind data and functions for encapsulation, so that programs can be developed more quickly and repeated code rewriting can be reduced.
Class and Object
The class is equivalent to the drawing when the plane is licensed, and the aircraft created with it is equivalent to the object
Class
Group by group
A set of entities with similar internal states and motion patterns (or collectively called abstract)