예제 #1
0
        public Charactor GetCharactor(string symbol)
        {
            Charactor c = hashTable[symbol] as Charactor;

            if (c == null)
            {
                switch (symbol.ToUpper())
                {
                case "A":
                    c = new CharactorA();
                    break;

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

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

                default:
                    c = new CharactorA();
                    break;
                }
                hashTable.Add(symbol, c);
            }

            return(c);
        }
예제 #2
0
        public void Test()
        {
            CharactorFactory factory = new CharactorFactory();

            // Charactor "A"
            CharactorA ca = (CharactorA)factory.GetCharactor("A");

            ca.SetPointSize(12);
            ca.Display();

            // Charactor "B"
            CharactorB cb = (CharactorB)factory.GetCharactor("B");

            cb.SetPointSize(10);
            cb.Display();

            // Charactor "C"
            CharactorC cc = (CharactorC)factory.GetCharactor("C");

            cc.SetPointSize(14);
            cc.Display();

            Console.ReadLine();
        }