CustomDialog
is the parent abstract class for OkExclamationDialog
and ExclamationDialog
with abstract method displayDialog()
being overriden.
Does this fall into a design pattern? Can this design be improved upon?
JudgeButton
controls the other classes.
public class JudgeButton {
private int typeCode;
private void initialise(){
setTypeCode();
if(typeCode == 0){
c = new ExclamationDialog("Episode not started");
c.displayDialog();
}
else if(typeCode == 1){
c = new OkExclamationDialog("Episode Finished, you will now be redirected");
c.displayDialog();
}
}
private void setTypeCode(){
wrapperJsonObject = Utils.getCurrentWrapperJsonObjectFromServer();
jsonObject = wrapperJsonObject.getJsonObject();
NextRatingsScreen n = new NextRatingsScreen(jsonObject);
RatingsCountDownTime r = new RatingsCountDownTime();
if(!n.isEpisodeStarted()){
typeCode = 0;
}
else if(!n.isPerformanceStarted()){
typeCode = 1;
}
}
}
public class OkExclamationDialog extends CustomDialog{
public OkExclamationDialog(String text) {
super(text);
}
public void displayDialog() {
DialogType dialogType = new DialogType();
DialogBuilder dialogBuilder = new DialogBuilder();
AbstractDialogFactory abstractDialogFactory = dialogType.getDialogType(DialogEnum.EXCLAMATION_DIALOG);
Dialog nextScreen = dialogBuilder.buildDialog(abstractDialogFactory, super.getText());
int result = nextScreen.doModal();
ScreenController.displayNextScreenFadeTransition(nextScreen);
if(result==Dialog.OK)
{
ScreenController.displayNextScreenFadeTransition(new ContestantsScreen());
}
}
}
public class ExclamationDialog extends CustomDialog{
public ExclamationDialog(String text) {
super(text);
}
public void displayDialog() {
DialogType dialogType = new DialogType();
DialogBuilder dialogBuilder = new DialogBuilder();
AbstractDialogFactory abstractDialogFactory = dialogType.getDialogType(DialogEnum.EXCLAMATION_DIALOG);
Dialog nextScreen = dialogBuilder.buildDialog(abstractDialogFactory, super.getText());
ScreenController.displayNextScreenFadeTransition(nextScreen);
}
}
public abstract class CustomDialog {
private String text;
public CustomDialog(String text){
this.text = text;
}
public String getText(){
return this.text;
}
public abstract void displayDialog();
}
r
is never used, so justnew RatingsCountDownTime();
should be sufficient. \$\endgroup\$