如何访问工厂方法创建的对象?

时间:2013-04-16 16:17:28

标签: java design-patterns instance factory-pattern

我的问题是如何通过没有名称的Factory方法访问实例cretead 这是我的代码

    public abstract class Vertex <T>{

int vertexId ;
T vertexValue ;

public  abstract  T computeVertexValue();}


    public class ImageVertex extends Vertex<Map<String, Instance>>{


public ImageVertex(int id ) {
    this.vertexId=id;
}

@Override
public Map<String, Instance> computeVertexValue() {
//  
}


    public abstract class AbstractVertexFactory<T extends Vertex>  {

public abstract  T createVertex(int id);}


    public class ImageFactory extends AbstractVertexFactory<ImageVertex> {

@Override
public ImageVertex createVertex(int id) {
    // TODO Auto-generated method stub
    ImageVertex imVertex=new ImageVertex(id);
    imVertex.computeVertexValue();
    return imVertex;
}}  


    public class ImageFactorySimulator {
public static void main(String[] args) {

    AbstractVertexFactory<ImageVertex> immFactory = new ImageFactory();

    ImageVertex imVertex = immFactory.createVertex(1);}}

我如何从模拟器类或任何其他类访问我的ID等于1的ImageVertex实例?

0 个答案:

没有答案