私のプロジェクトの最初の部分は、ハイパーグラフを構築することです
これは簡単に描いた UML ダイアグラムです
頂点クラス
public abstract class Vertex <T>{
int vertexId ;
T vertexValue ;
public abstract T computeVertexValue();
}
Imagevertex クラス
public class ImageVertex extends Vertex<Map<String, Instance>>{
public ImageVertex(int id ) {
this.vertexId=id;
}
@Override
public Map<String, Instance> computeVertexValue(){
return null;
}
}
AbstractVertexFactory
public abstract class AbstractVertexFactory {
public abstract Vertex createVertex(int id);
public Vertex produceVertex(int id) {
Vertex vertex = createVertex(id);
vertex.computeVertexValue();
return vertex;
}
}
ImageFactory クラス
public class ImageFactory extends AbstractVertexFactory {
@Override
public Vertex createVertex(int id) {
// TODO Auto-generated method stub
return new ImageVertex(id);
}
}
シミュレーター
public class ImageFactorySimulator {
/**
* @param args
*/
public static void main(String[] args) {
AbstractVertexFactory imFactory= new ImageFactory();
ImageVertex im = (ImageVertex) imFactory.createVertex(0);
}
}
シミュレーターでのキャストの使用は面倒です。どうすれば回避できますか?