What is an EntityFactory

Elliot Ford edited this page May 7, 2015 · 4 revisions

What is an EntityFactory?

An EntityFactory is used to create and manage entities and EntityContainers. It provides methods to create, kill, import, export and move between in-tree containers. JALSE provides a default implementation - DefaultEntityFactory!

Why is an EntityFactory needed?

An EntityFactory is needed to create and maintain entity instances (since Entity is an interface the factory will deal with its implementation). A factory can be used to maintain an entire tree (or sub-tree) as EntityContainer only moves in one direction (container -> entity -> container).

A factory can be used to create a different Entity system or just to use single entities.

Creating an Entity

EntityFactory has newEntity(UUID, EntityContainer) and should create the entity instance with the parent as the supplied target container.

Killing an Entity

EntityFactory hastryKillEntity(Entity) and this should be used to tell if the entity could actually be killed (immortal).

Internal Entity transfers

EntityFactory has withinSameTree(EntityContainer, EntityContainer) and this should be used to tell if the two containers are within the same tree. If two containers are within the same tree a internal transfer should be tried first with tryTakeFromTree(Entity, EntityContainer) (which may not be possible and require an import).

External Entity transfers

EntityFactory has exportEntity(Entity) which removes all references the Entity has to its container making it ready for transfer to a entirely different tree. If an entity is alive but has no parent association tryImportEntity can be called to try and import the entity into the tree (and all child entities).

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.