关于抽象工厂模式的问题 [英] Question about Abstract factory pattern

查看:146
本文介绍了关于抽象工厂模式的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我更改了这个问题,因为上一个没有回答.因此,我们具有此处描述的模式:
http://en.wikipedia.org/wiki/Abstract_factory_pattern [
工厂是否可能有不同的对象?

在这种情况下应该怎么做?

Hi,
I change the question, because the previous one did not answer. So, we have the pattern described here:
http://en.wikipedia.org/wiki/Abstract_factory_pattern[^]

Example for my question:

Abstract Factory - interface with the creation of defined opserations for each of the abstract object (eg IWidgetAbstractFactory)
Factories concrete - abstract factory interface implementations (eg GtkFactory, FltkFactory)
Abstract objects - an interface for the type of object (eg IButton, ICheckBox)
Concrete objects - implementation of an abstract object (eg GtkButton, GtkCheckBox, FltkButton, FltkCheckBox)
Client - uses only the abstract factory and abstract object (do not need to know the names of the specific classes).

My question:
What happened when GTK have "triangle button", and Fltk - does not.

Is it possible that factories have not the same objects ?

What should be done in that case ?

推荐答案

我不确定我是否理解您的问题.您是在说一个工厂有一个三角形按钮(实现IButton),而另一个工厂没有?那将是完全有效的,只有接口很重要.如果不是您的问题,请进行澄清.
I am not sure if I understand your question. Are you saying, that one Factory has a triangle Button (which implements IButton) and the other Factory does not? That would be perfectly valid, only the interface matters. If that was not your question, please reclarify.


在这种Trinagle Button的特定情况下,Triangle是按钮可以具有的形状.这是您要创建的按钮的形状方面.我认为这应该是按钮创建的输入.查看Wiki中的示例,它的paint方法决定如何呈现按钮.

对于您的问题,万一Gtk工厂需要Ftlk工厂不需要的其他东西,则gtk工厂的额外需求应作为单独接口的一部分.

GtkFactory将实现两个接口,而FltkFactory将实现IWidgetAbstractFactory接口.
In this specific case of Trinagle Button, Triangle is the shape a button can have. It is shape aspect of the button you are creating. I think it should be an input to the creation of the button. Looking at the example in wiki, its the paint method that decides how the button to be rendered.

To your question, in case Gtk factory needs something extra that Ftlk factory does not need, the additional need of gtk factory should be part of a separate interface.

GtkFactory would implement both interfaces and FltkFactory would implement IWidgetAbstractFactory interface.


这篇关于关于抽象工厂模式的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆