Archived

This topic is now archived and is closed to further replies.

Using function pointers, inevitable.

This topic is 5047 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Have the implimentation seperate from the data ofcourse, and friend both styles of implimentation, or pass the data to implimentation I guess?

Share this post


Link to post
Share on other sites
It sounds like you might be interested in the Strategy Pattern. Google for it.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites