+ 10

Polymorphism

Guys, polymorphism is when you make more than 1 inheritence of one superclass?

17th Mar 2019, 9:57 PM
Augusto Medri
Augusto Medri - avatar
1 Resposta
+ 22
• Polymorphism, which etymologically means "many forms," is the ability to treat an object of any subclass of a base class as if it were an object of the base class. A base class has, therefore, many forms: the base class itself, and any of its subclasses. If you need to write code that deals with a family of types, the code can ignore type-specific details and just interact with the base type of the family. Even though the code thinks it is sending messages to an object of the base class, the object's class could actually be the base class or any one of its subclasses. This makes your code easier for you to write and easier for others to understand. It also makes your code extensible, because other subclasses could be added later to the family of types, and objects of those new subclasses would also work with the existing code.
19th Mar 2019, 5:00 PM
Danijel Ivanović
Danijel Ivanović - avatar