I am searching for a design pattern to generate objects from a template object. In my game i have different kind of items which will be generated out of a template object.
Currently i solved it by inheritance where each template entity implements the method:
public Item generate(EntityManager em);
My inheritance structure is:
ItemTemplate -> creates an Item
|_ ArmorTemplate -> creates and Armor
|_ WeaponTemplate -> creates an Weapon
|_ ....and more ....
When i create a item i pass the entity manager to the template and i get a persisted object. E.g. an ArmorTemplate returns me a persisted Armor and so on.
If the item generation needs any specific entities i have to do a lookup inside the generation method. I would like to solve it with a container based solution where i can inject my needed EJBs and do not have to pass my entity manager through the creation workflow.
From Hibernate i get a List of template objects and i do not want to do a instanceof to call the correct factory method.
My current solution works, but feels not very elegant. Any input would be fine. ;-)
Thanks in advance. greetings, m