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); } }
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}."); }
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)); }