T
Tony Johansson
Hello!
The GUI class is fully responsible for all input from the user.The GUI input
is a registration of a animal
with name, age, animal category, type of animal and what kind of food this
animl like and so on.
There is a button Add in the GUI that make all validation to make sure that
all input is correct.
When hitting this Add button another methodb Add in the AnimalManager class
is called along with with all the input arguments.
Below is the AnimalManager class listed.
Now to my question is it any point to make any kind of validation before
adding the animal object to the animals collection
class AnimalManager
{
const int IDStart = 10;
private List<Animal> animals = new List<Animal>();
private CategoryType category;
private AnimalType animal;
private string name;
private double age;
private GenderType gender;
private HousingType housing;
private EaterType eater;
private bool aggressive;
private List<string> foodMenuList;
private string ID;
public AnimalManager()
{}
public void Add(CategoryType category, AnimalType animal, string
name, double age, GenderType gender,
HousingType housing, EaterType eater, bool aggressive,
List<string> foodMenuList)
{
this.category = category;
this.animal = animal;
this.name = name;
this.age = age;
this.gender = gender;
this.housing = housing;
this.eater = eater;;
this.aggressive = aggressive;
this.foodMenuList = foodMenuList;
ID = GenerateID(category,animal);
switch (category)
{
case CategoryType.Mammal:
IAnimal animalObj = MammalFactory.CreateMammal(animal, name,
ID, age, gender, housing, eater, false, foodMenuList);
animals.Add((Animal)animalObj);
break;
case CategoryType.Bird:
break;
case CategoryType.Insect:
break;
case CategoryType.Marine :
break;
case CategoryType.Reptile :
break;
}
}
private string GenerateID(CategoryType category, AnimalType animal)
{
int count = IDStart + animals.Count;
return category.ToString().Substring(0, 3) +
animal.ToString().Substring(0, 3) + count;
}
}
//Tony
The GUI class is fully responsible for all input from the user.The GUI input
is a registration of a animal
with name, age, animal category, type of animal and what kind of food this
animl like and so on.
There is a button Add in the GUI that make all validation to make sure that
all input is correct.
When hitting this Add button another methodb Add in the AnimalManager class
is called along with with all the input arguments.
Below is the AnimalManager class listed.
Now to my question is it any point to make any kind of validation before
adding the animal object to the animals collection
class AnimalManager
{
const int IDStart = 10;
private List<Animal> animals = new List<Animal>();
private CategoryType category;
private AnimalType animal;
private string name;
private double age;
private GenderType gender;
private HousingType housing;
private EaterType eater;
private bool aggressive;
private List<string> foodMenuList;
private string ID;
public AnimalManager()
{}
public void Add(CategoryType category, AnimalType animal, string
name, double age, GenderType gender,
HousingType housing, EaterType eater, bool aggressive,
List<string> foodMenuList)
{
this.category = category;
this.animal = animal;
this.name = name;
this.age = age;
this.gender = gender;
this.housing = housing;
this.eater = eater;;
this.aggressive = aggressive;
this.foodMenuList = foodMenuList;
ID = GenerateID(category,animal);
switch (category)
{
case CategoryType.Mammal:
IAnimal animalObj = MammalFactory.CreateMammal(animal, name,
ID, age, gender, housing, eater, false, foodMenuList);
animals.Add((Animal)animalObj);
break;
case CategoryType.Bird:
break;
case CategoryType.Insect:
break;
case CategoryType.Marine :
break;
case CategoryType.Reptile :
break;
}
}
private string GenerateID(CategoryType category, AnimalType animal)
{
int count = IDStart + animals.Count;
return category.ToString().Substring(0, 3) +
animal.ToString().Substring(0, 3) + count;
}
}
//Tony