public static void Run() { string text = " This is some random text. This needs to be represented in flyweight format"; CharacterContext ctx = new CharacterContext(); foreach (Char c in text) { FlyWeightCharacter fc = FlyWeightFactory.GetInstance().GetCharacter(c); Console.WriteLine(fc.GetFont(ctx)); } }
public FlyWeightCharacter GetCharacter(char key) { FlyWeightCharacter value; if (dict.TryGetValue(key, out value)) { return(value); } else { value = new FlyWeightCharacter(key); dict.Add(key, value); return(value); } }