C + + Summary: The basic concept of object-oriented

Source: Internet
Author: User

Object-oriented language

In freshman semester, we learned C language, it is a very classic, very basic language, all computer science students are not to escape its claws, and C + + from the name is very clear, it is a derivative of C, it almost includes all the contents of C, but their design ideas are very different, C is a process-oriented program, and C + + is an object-oriented program, let's explain the difference between the two.

process oriented:Analyze the steps required to solve the problem, and then use the function to step through the steps, the use of a one-time call in turn.
Object-oriented:is to break up the matter into individual objects, not to accomplish a single step, but to describe the behavior of something in the whole process of solving the problem.
For example, the process-oriented design is the first step in the analysis of the problem: 1, start the game, 2, Sunspot first go, 3, draw the screen, 4, Judge Win and lose, 5, turn to white son, 6, draw the screen, 7, Judge Win and lose, 8, return step 2,9, output the final result. The problem is solved by using separate functions for each of the above steps.
The object-oriented design is to solve the problem from another idea. The whole Gobang can be divided into 1, black and white both sides, the behavior of the two parties is exactly the same, 2, the Board system, responsible for drawing the screen, 3, the rule system, responsible for determining such as foul, winning and losing. The first Class object (Player object) is responsible for accepting user input, and informs the second class object (Checkerboard object) The change of the chess piece layout, the Checkerboard object receives the change of the chess piece to be responsible to show this change on the screen, and uses the third kind of object (rule system) to decide the chess game.
It is obvious that object-oriented is a function to divide a problem, not a step. The same is the game, the behavior in the process-oriented design scattered in the total number of steps, there is likely to be different drawing version, because the designers often consider the actual situation of a variety of simplification. In object-oriented design, the drawing can only appear in the Checkerboard object, thus guaranteeing the unification of the drawing.
The unity of function guarantees the extensibility of object-oriented design. For example, I want to join the Undo function, if you want to change the process-oriented design, then from the input to the judgment to show the sequence of steps to change, even the steps between the sequence of a large-scale adjustment. If it is object-oriented, only with the change of the Board object on the line, the board system to save black and white on both sides of the game, simple backtracking can be, and the display and rule judgment is not to be taken into account, while the entire function of the object call sequence has not changed, the change is only local.
For example, I want to change this Gobang game to go game, if you are process-oriented design, then the rules of Gobang distributed in every corner of your program, to change is not as good as rewriting. But if you are the object-oriented design, then you only change the rules of the object can be, Gobang and go is not the difference between the rules? (Of course the size of the chessboard is not the same, but do you think this is a problem?) Just make a small change to the Checkerboard object. The approximate steps of playing chess have no change from the object-oriented perspective.
Of course, to achieve the change is only a local need to design people have enough experience, the use of objects can not guarantee that your program is object-oriented, beginners or very poor programmers are likely to object-oriented virtual process-oriented reality, so that the design of the so-called object-oriented program is difficult to have good portability and scalability.

(This is the answer found on Baidu!) Not write their own, thank you to answer the question of the big guy!!! )

    • The basic concept of object-oriented

1. Object

The scientific Explanation: object in object-oriented method is an entity used to describe objective facts in the system, which is used to form a basic unit of the system. Objects consist of a set of properties and a set of behaviors.

Self-Explanation: for example, "people" is a very large concept, but specific to yourself, you are that object, there is a concrete meaning of the entity that, is the object, read the expression of the class, I hope you understood some, after all, the language is not good ...

2. Class

The principle of classifying many things into categories is abstract, that is, ignoring the non-essential characteristics of things, paying attention to the essential characteristics related to the current goal, and finding out the commonness of things, dividing things of a common nature into a class, and drawing an abstract concept, such as stone, trees, cars, houses, etc.

3. Packaging

Encapsulation is an important principle of object-oriented approach, which is to combine the properties and services of an object into a separate system unit and hide the inner details of the object as much as possible.

4. Inherited

Inheritance is one of the important reasons that object-oriented technology can improve the efficiency of software development, which is defined as: the object of special class owns all the properties and services of its general class, which is called the inheritance of the special class to the General class.

For example, we know the characteristics of a ship, and then consider the passenger liner, because it is known that the liner is also a ship, so it can be considered to have all the characteristics of the ship, so that only focus on the characteristics of the passenger liner unique.

5. Polymorphism

Polymorphism refers to a property or behavior defined in a generic class that, after being inherited by a particular class, can have different data, type or behave differently. (This is explained later in the context of a specific example!) )

    • Complete program Process

Related Article

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.

Tags Index: