
函数重载(overload & override)
python不支持函数重载(overload)。后定义的函数会直接覆盖之前定义的同名函数。
method-overriding-in-python
In Python method overriding occours simply defining in the child class a method with the same name of a method in the parent class.
- Call the original implementation of a method you are overriding whenever possible. This meakes the underlying API work as expected. When in need of skipping the call be sure to document the reasons.
- Always use super(cls, self) for Python 2.x or super() for Python 3.x to call the original implementation of a method. This respects the resolution order in case of multiple inheritance and, for Python 3.x, protects from changes in the class hierarchy.
- If you call to the original implementation of a method do it as soon as you have all the data you need to run it.
overload & override
overriding vs overloading # 这里管overload叫重载, override叫重写。
Overriding vs Overloading : http://www.differencebetween.com/difference-between-overriding-and-vs-overloading/
The method Overriding and method Overloading are two concepts/techniques/feature found in some programming languages. Both concepts allow the programmer to provide different implementations for methods with the same name. Method overriding allows the programmer to provide an alternative implementation within a sub class to a method already defined inside its super class. Method overloading allows the programmer to provide different implementations to multiple methods with the same name (within the same class).
difference:
- First of all, subjects of method overriding always stay within different classes, while subjects of method overloading stay within the same class.
- Another difference is that overridden methods have the same method name, method signature and the return type, but overloaded methods must differ in either the signature or the return type (the name should be the same).
- Another key difference is that overloading is resolved at compile time, while overriding is resolved at runtime.




近期评论