lundi 5 janvier 2015

Instantiate objects from instance of object

I am creating a game where characters can have modules attached to them which provide extra functionality, for example there could be a 'banker' module which listens for a click event and opens a menu for banking. Modules are user creatable by extending the Module class and registering an instance with a ModuleFactory. Modules are able to serialize themselves and load themselves from a serialized form (saving to XML) when is passed in the constructor.


The problem I am having is that when loading the modules I have the name and an instance of every module but I cannot make a new instance of each module.


Is it acceptable to make a newInstance() method inside of each module which returns an instance of the module? I know it is possible to use reflection for this but most of the time I find reflection to be more trouble than the benefits I get from it.






Aucun commentaire:

Enregistrer un commentaire