I have a design question about the evolution of an object (and its state) after completing some sequence of methods. I'm having trouble formulating what I mean, so I may need to clear the question based on feedback.
Consider an object called a classifier. It has the following methods:
void initialise() void populateTrainingSet(TrainingSet t) void pupulateTestingSet(TestingSet t) void train() void test() Result predict(Instance i)
My problem is that these methods need to be called in a specific order. Further, some methods are not valid until the previous method is called, and some methods are not valid after the method is called. For example, it would be unacceptable to call the prediction function () before calling test (), and it would be invalid to call the train () after calling the function ().
So far, my approach has been to maintain a private enumeration that represents the current state of the object:
private static enum STATE{ NEW, TRAINED, TESTED, READY};
But that seems a little vague. Is there a design pattern for this type of problem? Perhaps something is related to the template method.
source share