来自java编程思想
import java.util.Random;
class shape{
public void draw(){};
public void erase(){};
}
class circle extends shape{
public void draw(){
System.out.println("circle.draw");
}
public void erase(){
System.out.println("circle.erase");
}
}
class square extends shape{
public void draw(){
System.out.println("square.draw");
}
public void erase(){
System.out.println("square.erase");
}
}
class RandomShapeGenerator{
private Random rand = new Random();
public shape next(){
switch(rand.nextInt(3)){
default:
case 0:return new circle();
case 1:return new square();
}
}
}
public class FactoryTest {
}