# is there any different solution for different buildings different behaviours

I'm trying to make different behaviours for workers of different buildings, let's say an agricultural worker would need to sow wheat seed and collect the wheat grain when it's grown. let's call that Behaviour0

For carpentry a worker would get wood and make arrows.

I have 2 different behaviours and I would like to implement them all in the simplest way possible.

 class agricultural{
Workr Work
void Working(Work W){
Behaviour1();
}
}
class Carpentry{
Workr Work
void Working(Work W){
Behaviour2();
}
}
template <tipename T> class BuildWork{
T BW
Work(){
BW.Working();
}
}


I tried doing it with template so the behaviour would be inside agricultural and carpentry but problem occurred when I tried to declare template as only 1 can be inside it and getting it with ifs would make it the same as a non-templated version.

 class Workr{
// here I would need to make it only for 1 is possible
BuildWork <agricultural> BW
}


So is this how I should use it?

The next thing occurred to me is this

 class Building{
bool beh[2];
void Work(Workr W){
if beh[0]{
if (beh[1]){
behaviour0(Workr W);
}
else{
behaviour1(Workr W);
}
}
else{
if (beh[1]){
behaviour2(Workr W);
}
else{
behaviour3(Workr W);
}
}
}
}


The last code is workable but I wonder if there is a better solution for this? here I can just change the bits in the beh[ ] and it's working

Each building has different behaviours and each worker in that specific building has same behaviour. Specific behaviour is always in the same building type.

• You might want to revisit this question and describe what you're trying to achieve, the issue you have, and the solution you though about before introducing the code you use. – Vaillancourt Nov 30 '20 at 16:54
• So you want that in a specific building, you get any type of "worker" which would each have their own behaviour? – Vaillancourt Dec 1 '20 at 18:43
• each building has different behaviours and each worker in that specific building has same behaviour – MilitaryG Dec 2 '20 at 16:22
• Can a behaviour be present in different building types, or a specific behaviour is always in the same building type? – Vaillancourt Dec 2 '20 at 17:36
• Specific behaviour is allways in same building type – MilitaryG Dec 3 '20 at 16:10