A good Reference system can help your game
How many times has it happened where you have this one class, let’s say it’s a spaceship that was destroyed.
Now you have tell all other dependent objects that she died, any independent sprite animation class, AI, etc etc because they were relying on her. Another thing is, in my case, having a scene that contains all the objects and by deleting the ship It won’t get removed from the scene, keeping the reference alive and so Garbage collector won’t kick in. Deleting and removing from the list is a way, but why should you inside the spaceship class have know how to remove from the Scene list? Makes no sense. The list should know how to treat a deleted object.
I made a somewhat satisfactory solution.
A base class called Reference
So when you create your dependent spaceship objects you just do something like:
When you want to delete SpaceShip just do SpaceShip.DeleteThis(); and it will warn all dependent object that it’s being deleted
But how will the Dependent Object be aware of this?
On a list case you would remove that reference from the list.
This solution is obviously not the best but it turned out pretty great for my games. I don’t have to care how many dependence there are. I delete one and all objects will be warned. How they treat that warning is up to you.