Python Object-oriented programming

Source: Internet
Author: User

Programming Habits:

1. Include the document string as much as possible to make the program more organized.

2. The document string habit is a three-quote string ("" "). This allows you to extend the document of a program without changing the quotation mark style. (for example, add more rows)

3. If necessary (almost always), provide a constructor that initializes each object with meaningful values.

4, the first parameter of all methods is named Self, always follow this naming convention, to ensure that the Ptyhon program written by different programmers is consistent

Programming Error:

1, if the value returned from the constructor is not none, it is a serious run-time error.

2. Forgetting to set the object reference (usually the self parameter) to the first parameter in the method definition causes a serious logic error when the method is called at run time.

3. Directly accessing the properties of an object may cause data to enter an inconsistent state.

Programming Knowledge:

1, initialize the object first, and then let the client code call the method of the object, cannot rely on the client code to initialize the object correctly.

2. Using Access methods to control access to attributes, especially write access, helps ensure that the data is intact.

3. Access to data through the set and get methods not only avoids invalid data values, but also separates the client of the class from the representation of the data if the data represents a need to change (usually to reduce the amount of storage required to improve performance). You only need to change the method body-as long as the interface provided by the method remains the same, you do not have to change the customer.

Python Object-oriented programming

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.