Entity class
An entity is a uniquely identifiable object that serves as a container or identifier for components in a Dependency Injection (DI) or Entity-Component-System (ECS) framework.
Identity model (by design)
Entity is an integer-identifier value type, same model as Flutter's
Key. Two Entity instances with the same id are the same entity:
- hashCode is id by definition.
==compares by id (and so, for Entity values, by hashCode).Entity == nonEntityreturns true whenentity.id == objId(other). This is intentional — an Entity is interchangeable with any object that produces the same objId. It makes the Entity.obj factory andMap<Entity, ...>lookups symmetric.
Caveats this contract imposes on callers:
- Anything that produces the same id is the same entity to this
package. For TypeEntity in particular, id is the type-string's
hashCode— see TypeEntity for the collision caveat and the--minifycaveat. - Do not mix raw
int/Stringkeys withEntitykeys in the sameMap/Set. The package itself never does this —DIRegistry._stateisMap<Entity, ...>end-to-end.
Constructors
- Entity(int id)
-
Creates a new instance of Entity identified by
id. Theidmust be 0 or greater.const - Entity.obj(Object object)
-
Creates a new instance of Entity from the specified
object. This effectively uses objId to convert theobjectto an int and then uses that as the id for the new Entity instance.factory - Entity.reserved(int id)
-
Creates a new Entity with the given
id. Theidmust be less than 0.const
Properties
Methods
-
isDefault(
) → bool -
isNotDefault(
) → bool -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
preferOverDefault(
Entity other) → Entity -
Returns
otherifthisis DefaultEntity, otherwise returnsthis. -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override