0

I am trying to initialize each of the following where the Graph Object comes from the JUNG graph package (Factory comes from org.apache.commons.collections15):

        Factory<Graph<Integer, String>> graphFactory;
        Factory<Integer> vertexFactory;
        Factory<String> edgeFactory;

I need these three objects in the constructor of the BarabasiAlbertGenerator (click for JavaDoc) Object.

In my reading of the Factory Pattern, I see that it is used to pass off the instantiation of objects to subclasses. So, what I know is:

  1. There must be some class in the Jung Package that implements the Factory interface that can then instantiate the object I declare 'graphFactory'. Similarly for vertexFactory and edgeFactory

The question is (is what I am assuming correct as well) how do I instantiate these objects and which set of possible types could/would I use for instantiating each object?

4

1 回答 1

1

对于 graphFactory,您可以在所需的图形类上使用 getFactory() 静态方法。

您将需要编写 vertexFactory 和 edgeFactory 的实例。
您可以为顶点/边使用任何类型,这就是它们是通用的原因(这就是为什么您必须指定它们的创建方式)。:)
查看示例代码以获取示例。

于 2012-10-08T15:53:04.420 回答