[Java代码] //Shape.java文件 public interface Shape public (1) void display(); //XXCircle.jave文件 public class XXCircle public void displayIt() //省略具体实现
//Circle.java文件 public class Circle (2) Shape private XXCircle pcx= (3) ; public void display() pcx.displayIt();
//Factory.java文件 public class Factory public (4) getShapeInstance(int type) switch(type) case 1:return new Line(); case 2:return new Square(); case 3:return new Circle(); default:return null;
//Main.java文件 public class Main public static void main(String[]args) int type=1; Factory factory=new Factory(); Shape s; s=factory. (5) ; if(s==null) System.out.println("Error get the instance!"); return;