Unless you're saving your commands for some other nefarious purpose (i.e. they've got an undo operation and once they're carried out they get stuck on an undo stack in case the user wants to back out) what you're really after is some way of executing an arbitrary chunk of code based on a string.
One way of doing this is to use a map, or other associative array:
typedef std::map< std::string, command * > command_map;
command_map cmd_map;
where command is something like:
class command
{
public:
virtual ~command() {}
virtual void execute() = 0;
};
and then use that to look up and execute what command you want executed:
void execute_command_by_name( const std::string &cmd_name,
const command_map *cmd_map )
{
command_map::const_iterator iter( cmd_map.find() );
if( iter != cmd_map.end() && iter->second )
{
iter->second->execute();
}
}
If you really need some sort of creational pattern to generate commands then replace the pointer to the command in the map with a function or functor that creates commands and you'll get much the same effect. If you want to still go further you can even dynamically load the code for commands at runtime but how to do that is very OS specific.
Anwyay, I'm not sure that PROTOTYPE pattern is the one to use in this case - you don't really need an exemplar for your class to clone when you can use the original object. If you need to create commands, as I mentioned above, I'd personally use FACTORY METHOD rather than PROTOTYPE.
Cheers,
Ash
PS: Edit as I was actually talking about FACTORY METHOD not ABSTRACT FACTORY. Bum.