Process-oriented and object-oriented are both thoughts on software analysis, design and development, which guide people to analyze, design and develop software in different ways. In the early days, there was process-oriented thinking. As the scale of software expanded and the complexity of problems increased, the disadvantages of process-oriented thinking became more and more obvious. Object-oriented thinking emerged and became the current mainstream method. Both run through all stages of software analysis, design and development. The corresponding object-oriented are called object-oriented analysis (OOA), object-oriented design (OOD) and object-oriented programming (OOP). C language is a typical process-oriented language, and Java is a typical object-oriented language.
When thinking about problems in a process-oriented way, we first think about "how to implement it step by step?" and map the steps into methods, step by step, and finally complete it. This is suitable for simple tasks that don’t require too much collaboration. For example, how to drive? We can easily list the implementation steps:
1. Start the car 2. Put in gear 3. Step on the accelerator 4. Let’s go
Process-oriented is suitable for simplicity and does not require collaboration affairs. But when we think about more complex questions, such as "How to build a car?", we will find that it is impossible to list 1234 steps. That's because building a car is too complex and requires a lot of collaboration to complete. At this time, object-oriented thinking came into being.
Object-oriented (Object) thinking is more in line with human thinking patterns. The first thing we think about is "How to design this thing?" For example, when thinking about building a car, we first think about "How to design a car?" rather than "How to build a car step by step." This is a change in mindset.
1. Thinking about building a car with object-oriented thinking, we found that the car is composed of the following objects:
1. Tire
2. Engine
3. Car shell
4. Seat
5. Windshield
In order to facilitate cooperation, we find a tire factory to complete the steps of manufacturing tires, and an engine factory to complete the steps of manufacturing engines; this way , found that everyone can manufacture the car and finally assemble it at the same time, which greatly improves efficiency. However, when it comes to the specific assembly line operation of a tire factory, there are still steps, and it is still inseparable from process-oriented thinking!
Therefore, object-oriented can help us grasp and analyze the entire system from a macro perspective. However, the micro-operations specific to the implementation part (that is, each method) still need to be handled with a process-oriented approach.
We must not antagonize process-oriented and object-oriented. They complement each other. Object-oriented cannot be separated from process-oriented!
·Summary of object-oriented and process-oriented
Second, they are both ways of thinking about solving problems and ways of organizing code.
3. Process-oriented can be used to solve simple problems
4. Solve complex problems: use object-oriented grasp at the macro level, and still process-oriented at the micro level.
· Object-oriented thinking method
When encountering complex problems, first find nouns from the problem, then determine which of these nouns can be used as classes, and then determine the attributes and methods of the classes according to the needs of the problem. Determine relationships between classes.
Suggestions
1. Object-oriented has three major characteristics: encapsulation, inheritance and polymorphism, while process-oriented has no inheritance and polymorphism, and process-oriented encapsulation is just encapsulation Functionality, while object-oriented can encapsulate data and functionality. Therefore, the advantages of object-oriented are more obvious.
2. A classic metaphor: object-oriented is like rice with rice, and process-oriented is like fried rice with eggs. The advantage of rice bowl is that the "vegetables" and "rice" are separated, which increases the flexibility of making rice bowl. If you are not satisfied with the meal, change the meal; if you are not satisfied with the dish, change the dish. In software engineering terms, "maintainability" is better, and the coupling between "rice" and "dish" is relatively low.
The above is the detailed content of Java tutorial object-oriented and process-oriented. For more information, please follow other related articles on the PHP Chinese website!