babylon.models.components.base

Component protocol definition.

The Component protocol defines the base interface for all component types in the Entity-Component architecture. All concrete components must implement this protocol.

The protocol is runtime-checkable, allowing isinstance() checks at runtime.

Classes

Component(*args, **kwargs)

Protocol defining the interface for all component types.

class babylon.models.components.base.Component(*args, **kwargs)[source]

Bases: Protocol

Protocol defining the interface for all component types.

All components in the Babylon simulation must implement this protocol. The protocol requires a component_type property that returns a string identifier for the component type.

This protocol is runtime-checkable, meaning you can use isinstance() to verify that an object implements the Component interface.

Example

>>> class MyComponent(BaseModel):
...     model_config = ConfigDict(frozen=True)
...     @property
...     def component_type(self) -> str:
...         return "my_component"
...
>>> instance = MyComponent()
>>> isinstance(instance, Component)
True
property component_type: str

Return the component type identifier.

Returns:

A string identifying the type of this component. For example: “material”, “vitality”, “spatial”, etc.

__init__(*args, **kwargs)