import 'package:gobang/flyweight/chess.dart'; /// 棋子享元工厂(单例) class ChessFlyweightFactory { ChessFlyweightFactory._(); static final ChessFlyweightFactory instance = ChessFlyweightFactory._(); static ChessFlyweightFactory getInstance() => instance; final Map _cache = {}; Chess getChess(String type) { return _cache.putIfAbsent(type, () { switch (type) { case 'white': return WhiteChess(); case 'black': default: return BlackChess(); } }); } }