1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
namespace ConsoleApplication2 { class Program { static void Main(string[] args) { } } /* Flyweight イミュータブルなクラス(フィールド値が不変のような)を再利用する。 */ public class Flyweight{ } public class FlyweightFactory { private FlyweightFactory f = new FlyweightFactory(); private FlyweightFactory(){ } private System.Collections.Generic.Dictionary<int,Flyweight> dic = new System.Collections.Generic.Dictionary<int, Flyweight>(); public FlyweightFactory GetInstance() { return f; } public Flyweight GetFlyweight(int key) { Flyweight f = dic[key]; if(f == null) { f = new Flyweight(); dic.Add(key, f); } return f; } } } |