samspade
Member
Here is the scenario. I have a bunch of objects - locks, keys, doors, buttons, combo locks, levers and so on. These objects need to interact with each other. Doors and locks interact, levers and doors or locks interact, combo locks interact with their individual buttons, and so on. They connections can be arbitrarily deep or complex.
Here is the question. Should objects only pull data from objects, only push data to objects, or a mix of both?
In other words. Let's say a Lever is attached to Lock A and Lock B. Lock A is attached to Door A, and Lock B is attached to Door B. If Lever is in position 0, Lock B is locked, but Lock A is unlocked and Door A can be opened. If Lever is in position 1, Lock A is locked, but Lock B is Unlocked, and Door B can be Opened.
So I interact with Lever. Should Lever A push its data to Lock A, which then pushes it data to Lock B. Or should Lever just send out a note that an update is needed, and then Lock A checks, Lever A, and Door A checks Lock A?
What are the pros and cons of each? Right now I have it as a mix of both mostly as an artifact of creation. Occasionally, this results in me forgetting which way data goes and messing things up.
To generalize the question, if you have a complicated system of data where a bunch of things all connected to each other and their states rely on the states of the things they are connected to such that changing one state could cause a cascading effect, how would you handle that cascade of changes?
Here is the question. Should objects only pull data from objects, only push data to objects, or a mix of both?
In other words. Let's say a Lever is attached to Lock A and Lock B. Lock A is attached to Door A, and Lock B is attached to Door B. If Lever is in position 0, Lock B is locked, but Lock A is unlocked and Door A can be opened. If Lever is in position 1, Lock A is locked, but Lock B is Unlocked, and Door B can be Opened.
So I interact with Lever. Should Lever A push its data to Lock A, which then pushes it data to Lock B. Or should Lever just send out a note that an update is needed, and then Lock A checks, Lever A, and Door A checks Lock A?
What are the pros and cons of each? Right now I have it as a mix of both mostly as an artifact of creation. Occasionally, this results in me forgetting which way data goes and messing things up.
To generalize the question, if you have a complicated system of data where a bunch of things all connected to each other and their states rely on the states of the things they are connected to such that changing one state could cause a cascading effect, how would you handle that cascade of changes?