This should be an easy question but I think I don't know what the right keywords are to search by.
What's the best way in C++ to implement object recycling when the consumer/user of instances only knows them by a generic interface?
Example:
Class CTargetOfActions (holds state)
Pure virtual class CWidget, exposes function DoStuff(CTargetOfActions &Target)
Classes which implement/inherit from CWidget:
CRedWidget
CBlueWidget
CYellowWidget
The user of these classes gets them from a class factory which uses criteria the user doesn't understand to pick which one(s) to use and initialize them, then supply them as a vector of CWidget pointers.
So, what's the best way for the user to hand them back to the class factory for reuse when the consumer doesn't know exactly which type they are? Should CWidget have a member/property exposed revealing what type it is and the class factory a single Recycle(CWidget) call?
What's the best way in C++ to implement object recycling when the consumer/user of instances only knows them by a generic interface?
Example:
Class CTargetOfActions (holds state)
Pure virtual class CWidget, exposes function DoStuff(CTargetOfActions &Target)
Classes which implement/inherit from CWidget:
CRedWidget
CBlueWidget
CYellowWidget
The user of these classes gets them from a class factory which uses criteria the user doesn't understand to pick which one(s) to use and initialize them, then supply them as a vector of CWidget pointers.
So, what's the best way for the user to hand them back to the class factory for reuse when the consumer doesn't know exactly which type they are? Should CWidget have a member/property exposed revealing what type it is and the class factory a single Recycle(CWidget) call?