Ecco la mia regola aziendale:
Anyone (anonymous users) can make an Application (as in to apply for something). Applications can be updated until they are reviewed and approved by an officer. Approved applications cannot be updated.
Pertanto ho creato una classe astratta
abstract class Application {
//various fields of application form
//fields do not have setters, but they have getters
public enum State {APPROVED, UNAPPROVED};
public abstract State getState();
}
E poiché un'applicazione può essere in due stati, li ho modellati come:
public class ApprovedApplication extends Application{
//an approved application can only be created from an unapproved application
public ApprovedApplication(UnapprovedApplication ua) {
//create it
}
public State getState() {
State.APPROVED;
}
}
e
public class UnapprovedApplication extends Application{
//only unapproved applications can be updated
public void update(ApplicationDTO applicationDTO) {
//do the updating
}
public State getState() {
State.UNAPPROVED;
}
}
Sono sulla strada giusta qui o è questa spazzatura completa? E che dire dell'ufficiale che approva l'applicazione? Stai un po 'perso qui.
UnapprovedApplication.approve(Officer o);
o
Officer.approve(UnapprovedApplication ua); ?