My categorizer was very simple.
categorize(life) {
if (life.heart)
return animal
else
return plant
}
Then life grew complicated and more checks were added
categorize(life) {
if (life.heart)
if (life.onland)
return landanimal;
else
return wateranimal;
else
if (life.land )
return landplant
else
return treeplant
}
But stuff did not end there, soon animals became reptiles, mammals, etc. and if-else began to clutter.
What design pattern is suggested to work around this nested if-else complexity?