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 に答える