In factory design, when I create the new object with factory class I ask the user to his/her input and get the input from the user in factory class after that I create the object with these inputs.
Is it practicable to get the user input in factory class? How should I get user input in factory class?
The factory class is below;
Type *Factory::create_type(int Type){
switch(Type){
case 1:{
return new A(this->getUserTime(),this->getUserValue());
}
case 2:{
float min = this->getUserMin();
float max = this->getUserMax();
if(this->validMinMax(min,max))
return new B(this->getUserSpeed(),this >getUserValue(),min,max);
else
return NULL;
}
case 3:{
float min = this->getUserMin();
float max = this->getUserMax();
if(this->validUserMinMax(max,min))
return new C(this->getUserSpeed(),this->getUserValue(),max,min);
else
return NULL;
}
case 4:{
return new D(this->getUserDistance(),this->getUserSpeed(),this->getUserValue());
}
}}
One of inputs function in factory class;
float Factory::getUserValue(){
float m;
std::cout<<"\n enter value:";
std::cin>>m
return m; }
Aucun commentaire:
Enregistrer un commentaire