My dice simulator varies its UI depending on the user's input and the model. I have been trying to implement the Builder pattern to handle the variation and optional parameters, while allowing for the use of GroupLayout.
At the moment I am making a call like this in the Controller:
if ((model.simRolls <> null) && (inputEvent.getSource == outputBtn) && (model.testType.equals("Success"))) {
SimView outputScreen = new SimView.Builder(jframe, jpanel).testLabel("SUCCESS TEST OUTPUT", GroupAlignment.LEADING).outputLabel(model.simRolls, GroupAlignment.CENTER).actionButton("Next", GroupAlignment.TRAILING).build();
}
I hate the if statements because they are infinite in variety. Can anyone please help me understand what abstraction or contract or interface I can possibly use to cleanly and accurately build the required UI in the MVC?
Instead of trying to handle infinite combination in your
if-statement
, why don't break up the the clause into several more granular clauses? This way, if you add more new features, then you can easily add another small clause into your existing clauses without worrying about forgetting to handle yet-another-combination(s).For example:-