Dispatching in the object model is executing the correct code based on the type of a class. In this example, the age method is overloaded in the Student and Employee classes. Overloading occurs because the same name, age, is used for the methods in all three classes. There may be a reason for calculating the age of a Student or an Employee. For example, for insurance reasons, you may want the age of an Employee as of the first of the month instead of using today's date as might be defined in the Person class.
The object system ensures that the right method is executed on the right data. In other words, it is not possible to execute the wrong age method on the right data, or the right age method on the wrong data.
The ability to redefine methods on a class basis is known a polymorphism.
For this example, you should not see this type of case statement with an object system. It is handled by dispatching.
if type is Person then
... calculate age based on Person rules ....
else if type is Student then
... calculate age based on Student rules ....
else it type is Employee then
... calculate age based on Employee rules
More on the general topic: Inheritance Object Model Concept
Author: Douglas K Barry
You may use this material for your work or classes. Reprint Policy. Be sure to check the menu at the left for other articles available on this site.
The Savvy Manager's Guide
Douglas K Barry is also the author of a book that explains Web Services, service-oriented architecture, and Cloud Computing in an easy-to-understand, non-technical manner.
Web Services, Service-Oriented Architectures, and Cloud Computing: The Savvy Manager's Guide (Second Edition)
by Douglas K Barry with David Dick
This is a guide for the savvy manager who wants to capitalize on the wave of change that is occurring with Web Services, service-oriented architecture, and—more recently—Cloud Computing. The changes wrought by these technologies will require both a basic grasp of the technologies and an effective way to deal with how these changes will affect the people who build and use the systems in our organizations. This book covers both issues. Managers at all levels of all organizations must be aware of both the changes that we are now seeing and ways to deal with issues created by those changes.