Comparison between process-oriented and object-oriented games through wuziqi

Source: Internet
Author: User

For example, wuziqi, the process-oriented design is the first step to analyze the problem:

1. Start the game,
2. sunspots first,
3. Draw pictures,
4. Determine whether to win or lose,
5. It's white's turn,
6. Draw pictures,
7. Determine whether to win or lose,
8. Return to step 2,
9. output the final result.

The above steps are implemented using separate functions, and the problem is solved.

The object-oriented design solves the problem from another idea. The entire Wuzi game can be divided:

1. Both sides of the black and white sides share the same behavior,
2. The checkerboard system is responsible for drawing pictures,
3. The rule system is responsible for determining such as foul and win/lose.

The first type of object (Player Object) is responsible for accepting user input, and notifying the second type of object (board object) of the changes in the layout of the pawns, when the checker object receives the changes of the pawns, it is responsible for displaying the changes on the screen. At the same time, it uses the third type of objects (rule system) to determine the game board.

Yes
It is obvious that object-oriented is to divide the problem by functions rather than steps. The same is drawing board games. Such behavior is distributed across multiple steps in the process-oriented design, and different drawing versions may appear,
Because the designers usually take into account the actual situation for a variety of simplification. In the object-oriented design, plotting can only appear in the chessboard object, thus ensuring the unity of drawing.

Merit
Performance uniformity ensures the scalability of object-oriented design. For example, I want to add the regret function. If I want to change the process-oriented design, I need to change the input, judgment, and display steps.
The order between them must be adjusted on a large scale. If it is object-oriented, you only need to modify the checker object. The checker system saves the chess spectrum of both sides of the black and white, and simply backtrack the Board object. The display and rule judgment are not required.
While the calling sequence of the object function remains unchanged, the changes are only partial.

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.