Using function pointers, inevitable.

Started by
2 comments, last by The C modest god 20 years, 1 month ago
I would like to have a class which may have two different implementations which could be change during run time. In order to do so in a nice OO manner, I would have had to make two classes inheriting the original class and destroy and recreate the object in order to switch between the two implementations. This requires me to recreate the object which means recreating all the data within it, and that is time consuming. If there was a way to onky recreate the implementation part, without recreating the data part, and that the implementation part could still use the data part... Well, there is a way. But its not nice OO programming. The other way is to use pointers to functions and change the functions the pointers point to. Is there a way to do it in OO manner?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Advertisement
Have the implimentation seperate from the data ofcourse, and friend both styles of implimentation, or pass the data to implimentation I guess?
It sounds like you might be interested in the Strategy Pattern. Google for it.

"Sneftel is correct, if rather vulgar." --Flarelocke
What you''re looking for is the strategy pattern. Google on "strategy pattern", e.g.: http://home.earthlink.net/~huston2/dp/strategy.html

And do yourself a favor and by this brilliant book:
Design patterns

Regards,
Andre (VizOne) Loker
Andre Loker | Personal blog on .NET

This topic is closed to new replies.

Advertisement