As we have it currently, the way all subsystems are instantiated is with the following two functions:
public class Subsystem {
private static Subsystem currentInstance;
public static void init() {
if (currentInstance == null) {
currentInstance = new Subsystem();
}
}
public static Subsystem getInstance() {
init();
return currentInstance;
}
}
The problem with this design is from a testing perspective, you would want to re-initialize subsystems for each test, which would never happen because they won't re-initialize if there is already an instance.
There are two solutions I see to this problem:
Make it so that init() re-initializes a subsystem even if it already exists. The getInstance() method would not initialize the subsystem at all, it would just return currentInstance.
This is easy but I don't know if we want anyone to have the power to re-initialize a subsystem.
Create a helper method in tests which resets *everything` before a test.
This could be better actually because the way we could do it is by instantiating another robot, which is more accurate.
We would need to use reflection extensively however.
Which of these solutions do you prefer @eandr127?
I have already done #1 in the subsystem-factory branch if you want to see the full extent of what would change.
As we have it currently, the way all subsystems are instantiated is with the following two functions:
The problem with this design is from a testing perspective, you would want to re-initialize subsystems for each test, which would never happen because they won't re-initialize if there is already an instance.
There are two solutions I see to this problem:
init()
re-initializes a subsystem even if it already exists. ThegetInstance()
method would not initialize the subsystem at all, it would just returncurrentInstance
.Which of these solutions do you prefer @eandr127?
I have already done #1 in the
subsystem-factory
branch if you want to see the full extent of what would change.