[英]Is the below design an abstract factory?
I have the following scenario 我有以下场景
A method takes a vehicle type object and returns the following 方法采用车辆类型对象并返回以下内容
a. 一个。 Road vehicle b.
公路车辆b。 water vehicle c.
水车c。 flying vehicle.
飞行的车辆。
another method takes the object returned from 1 and gives more specific object. 另一种方法从1返回对象并提供更具体的对象。 For ex if "Road vehicle is returned" then this method will return Car, bus etc.
如果“道路车辆退回”,那么此方法将返回汽车,公共汽车等。
Can I say that this is an example of Abstract factory pattern? 我可以说这是抽象工厂模式的一个例子吗? Because in step 1 , I am getting one of possible factory and in step 2, it is more of specific object.
因为在步骤1中,我得到了一个可能的工厂,并且在步骤2中,它更具特定的对象。
Regards 问候
You're not creating a concrete factory first, so I don't see this as being a representation of abstract factory. 你不是先创建一个具体的工厂,所以我不认为这是抽象工厂的代表。 Thus you've got a concrete factory method.
因此,你有一个具体的工厂方法。
在这种情况下,您有一个工厂方法。
No yours is not an abstract factory, it is more of a Factory Method pattern . 不,你不是一个抽象工厂,它更像是一个工厂方法模式 。
Abstract Factory offers the interface for creating a family of related objects, without explicitly specifying their classes.
Abstract Factory提供了用于创建一系列相关对象的接口,而无需显式指定其类。
Something like this would be Abstract Factory 像这样的东西就是抽象工厂
interface CarSparePartFactory{
public SparkPlug createSparkPlug();
public Wheel createWheel();
}
interface SparkPlug{
}
interface Wheel{
}
Here you are creating a group of related objects using an interface. 在这里,您将使用界面创建一组相关对象。
For more on Abstract factory: 有关抽象工厂的更多信息:
It isn't. 事实并非如此。 An abstract factory should determine by itself the kind of object to be created.
抽象工厂应该自己确定要创建的对象的类型。 It's not supposed to be a parameter sent by the client.
它不应该是客户端发送的参数。 Otherwise, the main purpose of the abstract factory ("Provide an interface for creating families of related or dependent objects without specifying their concrete classes.") is not satisfied.
否则,抽象工厂的主要目的(“提供用于创建相关或依赖对象族的接口而不指定其具体类。”)不满足。
See more at http://en.wikipedia.org/wiki/Abstract_factory_pattern 有关详情,请访问http://en.wikipedia.org/wiki/Abstract_factory_pattern
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.