コード例 #1
0
    public Gem Create(string arguments)
    {
        var     tokens      = arguments.Split();
        var     clarityType = tokens[0];
        var     gemType     = tokens[1];
        Clarity clarity     = (Clarity)Enum.Parse(typeof(Clarity), clarityType);

        Gem gem = null;

        switch (gemType)
        {
        case "Ruby":
            gem = new RubyGem(clarity);
            break;

        case "Emerald":
            gem = new EmeraldGem(clarity);
            break;

        case "Amethyst":
            gem = new AmethystGem(clarity);
            break;
        }

        return(gem);
    }
コード例 #2
0
        public Gem CreateGem(GemTypes gemType, GemClarities gemClarity)
        {
            Gem gem = null;

            switch (gemType)
            {
            case GemTypes.Amethyst:
                gem = new AmethystGem(gemType, gemClarity);
                break;

            case GemTypes.Emerald:
                gem = new EmeraldGem(gemType, gemClarity);
                break;

            case GemTypes.Ruby:
                gem = new RubyGem(gemType, gemClarity);
                break;
            }

            return(gem);
        }