12.19

import java.util.Hashtable;

/**

 * 围棋棋子工厂类:享元工厂类

 *

 */public class IgoChessmanFactory {

    private static IgoChessmanFactory instance = new IgoChessmanFactory();

    private static Hashtable ht;

 

    public IgoChessmanFactory() {

        // TODO Auto-generated constructor stub

        ht = new Hashtable();

        IgoChessman black,white;

        black = new BlackIgoChessman();

        ht.put("b", black);

        white = new WhiteIgoChessman();

        ht.put("w", white);

    }

 

    public static IgoChessmanFactory getInstance(){

        return instance;

    }

 

    public static IgoChessman getIgoChessman(String color){

        return (IgoChessman)ht.get(color);

    }

 

}

posted @ 2023-12-20 09:47  秋渡晚枫  阅读(19)  评论(0)    收藏  举报