I am running a zoo application.
My zoo includes an abstract class of 'animal', and several deriving classes - 'zebra', 'elephant', 'orangutan', 'baboon' and so on. Of each class I have several instances.
My question is: I want to check out if two animal instances can mate.
The business logic is divided to two parts:
- I want to check if each mating partner is fit for mating, e.g. not too young or too old or sick etc.
- I want to check if the two partners match - e.g. a zebra cannot mate an elephant, but an orangutan can mate with a baboon.
I assume the first requirement would be implemented by an abstract function which would reside under the animal baseclass. But what about the second requirement?
How would you design the classes in the most general matter that adding new types of animals would not require much of an overhead?