Polymorphism

Of the three pillars of OOP, inheritance and encapsulation are nice to have but polymorphism is the true key to OOP's success. Polymorphism gives objects the most important feature of all: replaceability.

There are two forms of polymorphism: late-bound and typed. Visual Basic uses late-bound, whereas Java uses typed. Python polymorphism is a hybrid of the two.

Late-Bound Polymorphism

In Python, late-bound polymorphism means that class instances can appear to be other objects if their class implements special methods. Thus, because a function is an object, a class can act like a function just by implementing a special method. Numeric types are also objects, so with special methods a class can act like a numeric type.

For example, ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.