Advanced PowerBuilder

HomePrevious Lesson: Benefits of Encapsulation
Next Lesson: Overloading

Polymorphism

In simple words, Polymorphism is the ability of a function to behave differently, depending on the context in which it is called.

Consider the example of calculating the salary of an employee. An employee can be a worker, a sales person, a manager, etc.. The calculation for each employee might be different. To implement this, you need to use either CASE or if.. else if., to call different versions of ComputePay() function. Using the CASE statements becomes a nightmare when modifying the system, since, each CASE statement needs to be updated. Polymorphism gives you the flexibility of avoiding the CASE and if.. else if statements. Here, at run-time, the compiler takes care of calling the appropriate function depending on the context in which the function was called.

Polymorphism can be implemented in two ways:

HomePrevious Lesson: Benefits of Encapsulation
Next Lesson: Overloading