Пример #1
0
        public Charactor GetCharactor(string key)
        {
            Charactor charactor = _charactors[key] as Charactor;

            if (charactor == null)
            {
                switch (key)
                {
                case "A":
                    charactor = new CharactorA();
                    break;

                case "B":
                    charactor = new CharactorB();
                    break;

                case "C":
                    charactor = new CharactorC();
                    break;

                default:
                    break;
                }
                _charactors.Add(key, charactor);
            }
            return(charactor);
        }
Пример #2
0
        public void TestFlyweight()
        {
            CharactorA ca = CharactorFactory.Instance.GetCharactor("A") as CharactorA;

            ca.SetPointSize(11);
            ca.Display();

            CharactorB cb = CharactorFactory.Instance.GetCharactor("B") as CharactorB;

            cb.SetPointSize(12);
            cb.Display();

            CharactorC cc = CharactorFactory.Instance.GetCharactor("C") as CharactorC;

            cc.SetPointSize(13);
            cc.Display();
        }