I have the following problem: I'm designing a game and summing up let's say that I have three classes:
Some "use cases"
And the only way I can get this to work, is that Player knows about PowerPlants and Units, but also each PowerPlant and Unit knows about his Player/Owner, so that they can communicate in both ways.
I somehow think that this is a code smell... when I have been in similar situations, I always have had trouble at the long term.
Thanks in advance.
The universal law of gravitation states that every object exerts a gravitational force of attraction on every other object.
Explanation: Newton's Third Law states that when two objects interact, they produce equal and opposite forces on each other. As a result, any force exerted on one body is often counterbalanced by an equal and opposite force exerted on the interacting partner.
Positively charged objects and neutral objects attract each other; and negatively charged objects and neutral objects attract each other.
I have had that problem in multiple occasions, and what you said is not necessarily an anti-pattern but it does add undesired complexity.
YMMV, but in my case, I didn't really wanted to have a direct relationship between those different classes but a way to notify each other when something happens, so the cleaner way I had found was having an event manager (or any other sort of callback mechanism) to glue all logic parts together. With that tool in the belt it turned out that I could get rid of all those double references which simplified the hierarchy a lot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With