public class aa {
public static void playGame(GameFactory factory) {
Game s = factory.getGame();
while (s.move())
;
}
interface Game {
boolean move();
}
interface GameFactory {
Game getGame();
}
class Checkers implements Game {
private int moves = 0;
private static final int MOVES = 4;
public boolean move() {
print("Checkers moves " + moves);
return ++moves != MOVES;
}
}
class CheckersFactory implements GameFactory {
public Game getGame() {
return new Checkers();
}
}
private void print(String string) {
// TODO Auto-generated method stub
print(string);
}
public static void main(String[] args) {
playGame(new CheckersFactory());//这行出错了
}
}
相关分类