Three main features of an object:
The behavior of an object. Which operations can be performed on the object or the methods that can be applied to the object.
The state of the object. How does the object respond when the method is applied.
The identity of an object.
Relationships between classes:
Dependency ("Uses-A") if a class method is used to manipulate the object of another class, we will say that one class depends on another class.
Minimize the number of dependent classes, even if the coupling between classes is the least.
Aggregate ("has-a") objects of Class A include objects of Class B.
Inheritance ("is-a") Class A inherits class B. Class A not only contains methods inherited from Class B, but also has some additional functions.
Comparison between OOP and traditional procedural programming technologies:
In procedural programming
First, determine the task to complete;
Then:
1. Use the process of gradual refinement: the tasks to be completed are divided into several tasks, and the subtasks are then divided into smaller subtasks, until the subtask is small enough to be directly implemented (this is the top-down method ).
2. Compile methods for solving simple tasks and assemble them into more complex processes until the functions to be implemented are completed (this is a bottom-up method ).
In procedural programming, the methods for determining a process are basically the same as those for determining a method in OOP, that is, to view verbs or actions in the Problem description. The most important difference in OOP is to first separate classes from projects and then find out which methods need to be defined in this class. Another difference is that in OOP, each method is associated with the class responsible for executing this operation.
It is more appropriate to use a procedural method with a small scale;
Large-scale usage classes and methods will bring two benefits:
1. classes provide a mechanism to facilitate the aggregation of many methods;
2. The class encapsulation mechanism will help hide data representation for other class methods;