Is cyclical referencing bad practice?

122 views Asked by At

Say I have three classes: EntityManager, Entity, and Component.

Entity has an array of components (pointers), and each of these components have a field that is a pointer to the encapsulating Entity.

EntityManager has an array of entities, and each entity has a pointer to its encapsulating EntityManager.

The reason for this design is data reliance. Components need access to the encapsulating entity's fields and some components depend on other entity's fields (pointer to entity manager).

Is this "cyclical" design a bad practice? Should I rethink my design?

1

There are 1 answers

0
JoeManiaci On

Anything cyclical is only bad in regards to resource shared/locking resources, particular in regards to multithreading.

Besides, it doesn't even look like this is cyclical. It's more of a side by side design, that is of course that to get EntityManager fields, a Component has to go through the Entity. Or, to get a Component, an EntityManager has to go through an Entity.

In terms of design I would worry about what happens if you need to change the fields of an EntityManager that an Entity or Component are dependent on?