[英]How can I design a complex GUI employing both builder design pattern and abstract design pattern?
I am trying to create a complex GUI, let's say the main panel containing a list panel and button panel.我正在尝试创建一个复杂的 GUI,假设主面板包含一个列表面板和按钮面板。 The button panel would again contain a couple of buttons.
按钮面板将再次包含几个按钮。 The construction sequence would be something like this:
构建顺序将是这样的:
constructMainPanel()
constructListPanel(mainpanel)
constructButtonPanel(mainPanel)
constructButton('b1',buttonPanel)
constructButton('b2',buttonPanel)
This GUI would have 2 styles: Linux and Windows.这个 GUI 有 2 种风格:Linux 和 Windows。 How can I design this GUI using both builder design pattern and abstract factory design pattern?
如何使用构建器设计模式和抽象工厂设计模式设计此 GUI? How would the class diagram look like?
类图会是什么样子?
I understand the builder and abstract factory patterns, but how can I use them together.我了解构建器和抽象工厂模式,但我如何将它们一起使用。 This is the builder pattern I refer to builder pattern wiki .
这是我参考builder pattern wiki 的构建器模式。 This is the abstract factory pattern I refer to abstract factory wiki
这是我参考abstract factory wiki的抽象工厂模式
The two patterns would cooperate as follows:这两种模式将按如下方式合作:
It's difficult to be more specific/precise, since each of this patterns has variations.很难更具体/精确,因为每个模式都有变化。 But it would probably look like (pseudocode):
但它可能看起来像(伪代码):
factory = new LinuxGUIFactory ();
builder = new ListChoiceBuilder (factory) // inject the factory
builder.buildPanels()
builder.buildApproveCancelButtons();
form = builder.GetResult();
The ListChoiceBuilder
would use as constructor parameter the abstract factory. ListChoiceBuilder
将使用抽象工厂作为构造函数参数。 It would then call the abstract methods of the abstract factory whenever it needs to create a panel, list panel, button,...然后它会在需要创建面板、列表面板、按钮等时调用抽象工厂的抽象方法。
When you instantiate ListChoiceBuilder
, you provide either the Linux, the Windows or the MacOs concrete factory, which uses exactly the same interface as the abstract factory.当您实例化
ListChoiceBuilder
,您提供 Linux、Windows 或 MacOs 具体工厂,它们使用与抽象工厂完全相同的接口。 Of course, the builder is an overkill for such a simple GUI example.当然,构建器对于这样一个简单的 GUI 示例来说是一种矫枉过正。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.