Saturday, January 12, 2008

Design and Implementation Idea of POLYMORPHISM in C [ non - object oriented language] Part IV

DISCUSSION –

1.A function pointer restricts (via the function prototype) the type of parameters passed to the function it is pointing to. One can use void pointer parameters to allow for varying parameter types, but this decreases the code readability (i.e. function prototypes include void pointer arguments instead of meaningful types) and disables parameter type checking.

2.Code Reuse is largely possible. If some new type comes in we don’t need to modify the original source code.

3.User programming is relatively simpler ... but implementation programming is quite difficult because of the large number of referencing and dereferencing of pointers to function that are highly required here.

4.Polymorphism thus obtained can be used with other data structure objects as well. It can be used with more then one layer of dependence i.e. objects hierarchy.


Another Approach -

Another approach is to introduce a common structure, which will be passed as parameter to the polymorphic function, hiding all type-dependant data in a special field of this structure. This special field is usually a void pointer or a union and is used as private storage space for each implementation of the polymorphic function.


This is all for polymorphism in C for time being. Hope you would benefit from the post. Do write me your suggestions and remarks.

xoxo
aL

1 comment:

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Home Theater, I hope you enjoy. The address is http://home-theater-brasil.blogspot.com. A hug.