Architect path (4)-detailed object-oriented

Source: Internet
Author: User

3.5 Object-Oriented Programming (OOP)

3.5.1 What Is Object-Oriented
When people are new to programming, most people may instinctively reflect process-oriented (OP) rather than object-oriented (OO. This phenomenon is actually quite normal. Changing the Way of Thinking requires a process. I have summarized the reasons for its formation:

1. Cause
You have not developed the habit of object-oriented analysis and problem solving. It takes some time to train and speculate on how to establish an object-oriented mindset. Therefore, you can deliberately strengthen this awareness in learning or in specific projects. Under normal circumstances, after a period of time, you will feel that this is a natural thing, only OO in your heart, naturally OO in your eyes.

2. Historical Reasons
We were trained from an early age to analyze and solve problems in the process-oriented (OP) approach, especially in mathematics. Most of the training focuses on solving problems step by step, the development of computer software has always been related to mathematics. Therefore, it is natural to bring the process-oriented (OP) method into software development.

What is object-oriented, or talk about your understanding of object-oriented, which may be the most common issue for software developers, especially programmers and designers. The corresponding English language of object-oriented is object-oriented, which translates object-oriented into "Object-Oriented". I always think this translation method is not accurate, for the first time, it is difficult for most people to understand the meaning of "Object-Oriented. Later, I checked some related information and found that the computer books in Hong Kong, Macao and Taiwan translated it into "object-oriented". I feel good about this translation method, in my heart, I am quite confused. "Object orientation" accurately reflects that object-oriented recognition and problem solving all focus on objects.

Therefore, the object-oriented thinking method holds that the software system is a set of interactive objects. A group of related objects are combined into a subsystem, and a group of subsystems are combined into more complex subsystems until they are combined into the entire system.

The starting point of the object-oriented approach is to simulate human habits as much as possible, and abstract the content involved in the "problem domain" into "object ", make software development methods and processes as close as possible to human understanding of the methods and processes of solving problems in the world.

Process-oriented is to analyze the steps required to solve the problem, and then use functions to implement these steps Step by step. You can call these steps one by one. Object-oriented refers to dividing a problem transaction into various objects. The object is created not to complete a step, but to describe the behavior of a thing in the whole process of solving the problem.

The process-oriented thinking can be referred to as the process theory, which focuses on the process steps. The process is the core of the entire system.

Object-oriented thinking can be called Assembly theory. It focuses on the abstraction and extraction of objects, and then assembles objects into a whole.

Therefore, Oo and OP have completely different starting points in terms of their way of thinking.

3.5.2 op PK oo
Let's use the example of playing chess to compare op and OO:

 

 
RED: Kung Fu pandatv Black: pijiao tiger REFEREE: guixiangren

The process-oriented (OPP) design concept is adopted. First, the entire combat process is split and the steps of the two sides are analyzed. The following process is obtained:
 

 

 

 

Implement each of the above steps using functions, and the problem is solved.

 

Let's take a look at how object-oriented solves the problem. The entire chess game can abstract three types of objects:
1. The gamer is responsible for playing chess. The two are consistent in behavior.
2. The Board is responsible for drawing the board screen.
3. The referee is responsible for determining, for example, eating a child, foul, and winning or losing.

The relationship between the three is as follows:

 

 
The first type of object chess player is responsible for playing chess, and informs the second type of object chess board about the changes in the layout of the chess board. After the Board receives the changes in the layout of the chess board, it is responsible for drawing the screen, meanwhile, the third-Class Object referee is used to determine the game board.
The following two implementation methods are available:

1. maintainability
Object-oriented divides Problems Based on Data and functions, rather than based on processes and steps. Similarly, the process-oriented design is dispersed in many steps and may appear in different drawing versions, it's just not like an egg in an "fried rice? In the object-oriented design, the drawing can only appear in the checker object, thus ensuring the unity of the drawing. This is the effect of separating the eggs from the "fried rice.

2. scalability
If I want to add the repentance function, and if I want to change the process-oriented design, I need to change the steps from playing the game to displaying and determining the process, even steps must be adjusted on a large scale in sequence. If it is object-oriented, you only need to modify the checker object. The checker object stores the chess spectrum of both sides, which can be simply traced back and reduced by one, and the display and determination are not involved, at the same time, the calling sequence of each object function is not changed as a whole, and the changes are only limited to partial.

3.5.3 deep thoughts on OO
OO believes that the software system is a set of interactive objects.
Since humans are very familiar with the real world, oo maps the problem domains to the real world in an abstract way, and tries its best to simulate everything in the real world. In this way, you can use the solutions and processes in the real world to solve problems in the software field.
Some people say that everything is an object in the eyes of OO. This sentence makes sense.
What benefits does oo bring to software development? How can we grasp the abstract scale of OO? This is a problem.

 

(To be continued)
---------------------------------------------------------------------------
Note: I am tired today. Write it here. When I went home in the evening, I met two blond beauty and they are from USA. They want to go to 2nd Foreign Language Colledge, but did not know how to get there. I told them the correct route in English. after studying English for so many years, I finally helped my international friends.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.