Polymorphism - Objective C
The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance.
Objective C polymorphism means that a call to member function will cause different function to be executed depending on the type of object that invokes the function.
Consider the example, we have a class Shape that provides the basic interface for all the shapes. Square and Rectangle are derived from the base class Shape.
We have the method printArea that is going to show about the OOP feature polymorphism.
In the above example based on the availability of the method calculateArea and printArea, either the method in the base class or the derived class executed.
Polymorphism handles the switching of methods between the base class and derived class based on the method implementation of the two classes.
Objective C polymorphism means that a call to member function will cause different function to be executed depending on the type of object that invokes the function.
Consider the example, we have a class Shape that provides the basic interface for all the shapes. Square and Rectangle are derived from the base class Shape.
We have the method printArea that is going to show about the OOP feature polymorphism.
In the above example based on the availability of the method calculateArea and printArea, either the method in the base class or the derived class executed.
Polymorphism handles the switching of methods between the base class and derived class based on the method implementation of the two classes.
No comments: