Home‎ > ‎

Home Page - 2003-04-27

posted 28 Nov 2008, 19:55 by S V Ramu   [ updated 29 Nov 2008, 04:04 ]
What would be Polymorphism in C ?! [Read this article]

Polymorphism in java is pretty straight forward. In fact puristic. Java doesn't consider methods as first-class citizens of its OO world. Methods have meaning only as a part of a class. If you want to pass a method as parameter, you have to create an interface and/or a class to pass that method. This is very distinct from the function pointer notion of C, Delphi (Object Pascal) or C#...

...The array (or a struct if you want) of function pointers is what can be compared to present day class. If a class is a collection of variables and functions, then since a function too can be represented as a (special pointer) variable, we can represent the class as an array of variables and function pointers. Can inheritance then be modeled as adding new function pointers, or replacing a old one?! Of course this doesn't give the elegance that a java like language provides, but for understanding the roots of OOP, function pointers, and arrays of it, is the key.