Basic OO programming skills -- (1)

Source: Internet
Author: User
Basic skills of OO programming (1)

This series will talk about the basic skills of some OO programming languages.

The basic skills of programming determine the code quality, programming ideas, and programming level, which is the top priority in the work. This article begins with an introduction to the basics and highlights of OO programming-ensuring abstract consistency.

 

Code

What is code? The process of converting a requirement into a software environment that can be correctly executed is called programming. The specific process for implementing this programming is called code writing. In the OO programming world, writing code is like writing story, and writing an article from abstraction to concrete.

To illustrate the purpose of this article-to ensure the consistency of abstraction, we will take the comparison of code, story, Code, and article as an example in this series.

 

Write code and story

 

A good implementation:


 

 


The Code on the left reflects the center of gravity that should be grasped during programming --Abstract layers must be consistent(In this example, the abstraction level is domain level ). The unqualified code may be written as follows:

 

 


We can see that the implementation code abstraction layers are uneven, and the abstraction layers of checkpassword are obviously lower than that of user. pay because it is a user. the specific implementation of login; while the user. order. status indicates user. the specific implementation of saveorder. The abstract layers of the Code are inconsistent, which not only reduces readability, but also brings maintenance costs and difficulty of expansion.

 

Write code and write articles

Code implementation with the same Abstraction:

 


Implementation of chaotic abstraction layers:

 


First, the login abstraction level is domain-level. In the same method, the implementation of Order and payment are exposed. The abstraction layers are obviously inconsistent. Therefore, this code must be reconstructed.

 

Conclusion:

It can be seen that code is the same as writing articles, from abstraction to concrete, and the abstraction levels are reduced in turn. In the same function, the abstraction layers of code calls should be consistent. For a linear flow, follow the steps from abstraction to specific steps to "translate". For parallel flows (in no particular order), you can also consider multithreading for optimization.

 

In OO programming, the key to designing classes, interfaces, and functions is that the abstraction layers must always be consistent.

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.