Esempio n. 1
0
        public string AddDwarf(string dwarfType, string dwarfName)
        {
            if (dwarfType == "HappyDwarf")
            {
                var dwarf = new HappyDwarf(dwarfName);
                dwarfs.Add(dwarf);

                return(String.Format(OutputMessages.DwarfAdded, dwarfType, dwarfName));
            }
            if (dwarfType == "SleepyDwarf")
            {
                var dwarf = new SleepyDwarf(dwarfName);
                dwarfs.Add(dwarf);
                return(String.Format(OutputMessages.DwarfAdded, dwarfType, dwarfName));
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidDwarfType);
            }
        }
Esempio n. 2
0
        public string AddDwarf(string dwarfType, string dwarfName)
        {
            IDwarf currDwarf = null;

            if (dwarfType == "HappyDwarf")
            {
                currDwarf = new HappyDwarf(dwarfName);
            }
            else if (dwarfType == "SleepyDwarf")
            {
                currDwarf = new SleepyDwarf(dwarfName);
            }
            else
            {
                throw new InvalidOperationException("Invalid dwarf type.");
            }
            dwarfs.Add(currDwarf);
            return($"Successfully added {dwarfType} named {dwarfName}.");
        }
Esempio n. 3
0
        public string AddDwarf(string dwarfType, string dwarfName)
        {
            IDwarf dwarf;

            switch (dwarfType)
            {
            case "HappyDwarf":
                dwarf = new HappyDwarf(dwarfName);
                break;

            case "SleepyDwarf":
                dwarf = new SleepyDwarf(dwarfName);
                break;

            default:
                throw new InvalidOperationException(ExceptionMessages.InvalidDwarfType);
            }
            dwarfs.Add(dwarf);

            return(string.Format(OutputMessages.DwarfAdded, dwarfType, dwarfName));
        }