I have two classes. 1. Node 2. MixedStateManager
Node class:
Node class maintains the state of nodes in the system. One such data is state.
public class Node
{
private int state;
public void setState(int s)
{
state = s;
}
public int getState()
{
return state;
}
}
MixedStateManager:
MixedStateManager sees if all the nodes in the system are in the same state or not. If the nodes don't have the same value for state value, then the system is said to be in MixedState. I've a variable mixedState for the same. I've made it static because, if the value is changed by one instance of the class, then it should be visible by others. Another thing to note is MixedStateManager is called by different threads which change the value of state of nodes.
public class MixedStateManager{
public static boolean mixedState;
public boolean isMixedState(){
return mixedState;
}
public void setMixedState(){
// get all instances of Node class;
if state of all instances are same
mixedState = true;
else
mixedState = false
}
}
Question: As MixedStateManager has only one data which is static, does it make sense to instantiate this class and then set value. Or can I make all methods static too?
Responses will be appreciated. Thanks