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