Python-learning Note 1-object-oriented Programming

Source: Internet
Author: User

1, object-oriented Most important concepts are classes (class) and instances (Instance), classes are abstract templates, and instances are based on the class created by a specific "object", each object is have the same method , but their data may be different.

2, in the class of the internal definition of access to the data function, the data encapsulated, these and class data associated with the function, called the method of the class.

3, __ The variable is a private variable, only internal access, if you want to modify the external code, you can add methods Inside.

4, after inheritance, the subclass has all the functions of the parent class (method), another benefit of inheritance is polymorphism: open to the Extension--can be added to the parent class subclass, the modification is closed--do not need to modify the dependent parent class function (open and close Principle)

5.

For a static language, such as java, if an incoming Animal type is required, the incoming object must be a Animal type or its subclass, otherwise the method cannot be called run() .

For dynamic languages such as python, the incoming type is not necessarily required Animal . we just need to make sure that the incoming object has a run() method.

The characteristics of duck type in dynamic language determine that inheritance is not necessary as a static language.

Python-learning Note 1-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.