什么是有用的抽象/契约来协助 Builder 模式构建 MVC UI?
我的骰子模拟器会根据用户的输入和模型改变其 UI。我一直在尝试实现 Builder 模式来处理变化和可选参数,同时允许使用 GroupLayout。
目前我正在控制器中进行这样的调用:
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();
}
我讨厌 if 语句,因为它们的种类是无限的。谁能帮我理解我可以使用什么抽象、契约或接口来干净、准确地在 MVC 中构建所需的 UI?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与其尝试在
if 语句
中处理无限组合,为什么不将 the 子句分解为几个更细粒度的子句呢?这样,如果您添加更多新功能,那么您可以轻松地将另一个小子句添加到现有子句中,而不必担心忘记处理另一个组合。例如:-
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:-
通常,您会安排视图将自身注册为模型的观察者,如本示例中所建议的。该布局只有实际使用它的视图才知道。
Typically, you arrange for a view to register itself as an observer of a model, as suggested in this example. The layout would be known only to a view that actually uses it.