コード例 #1
0
ファイル: CharacterFactory.cs プロジェクト: Opentany/Tech
 public Character GetCharacter(char key)
 {
     // Uses "lazy initialization"
     Character character = null;
     if (_characters.ContainsKey(key))
     {
         character = _characters[key];
     }
     else
     {
         switch (key)
         {
             case 'A': character = new CharacterA(); break;
             case 'B': character = new CharacterB(); break;
             //...
             case 'Z': character = new CharacterZ(); break;
         }
         _characters.Add(key, character);
     }
     return character;
 }
コード例 #2
0
        public Character GetCharacter(char key)
        {
            // Uses "lazy initialization"
            Character character = null;

            if (_characters.ContainsKey(key))
            {
                character = _characters[key];
            }
            else
            {
                switch (key)
                {
                case 'A': character = new CharacterA(); break;

                case 'B': character = new CharacterB(); break;

                //...
                case 'Z': character = new CharacterZ(); break;
                }
                _characters.Add(key, character);
            }
            return(character);
        }