Encapsulation and Polymorphism

---Restore content begins---

One.property

property is a special property, accessing it will execute a functional function and then return the value

two. polymorphism

①What is polymorphism

Polymorphism means multiple forms of the same thing

②Why use polymorphism

Use the base class to create a set of agreed rules and force subclasses to abide by them (implemented using abstract classes), so that the methods under the object can be used directly without considering the specific type of the object 

③ You can use the method of the object directly without considering the specific type of the object

three. classmethod and staticmethod

1. Binding method:

          The function defined inside the class is used by the object by default, and it is bound to the object, which is called the binding method of the object

The methods of binding objects are special:

             Should be called by the object, the object is called, the object will be automatically passed in as the first parameter

Binding class methods are special:

        Should be called by the class, the class call will automatically pass the class as the first parameter

2.staticmethod: an unbound method, which is an ordinary function

Features: neither bound to a class nor an object, which means anyone can use it

Whoever uses it is an ordinary function, which means that there is no automatic value transfer feature.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324589036&siteId=291194637