G
grahamo
This came up in an interview I did a while ago and I wanted to know
the correct answer. The setup is this;
If I have a base class "food" and also two classes "meat" and "veg"
that inherit from food, thus;
food
/ \
/ \
meat veg
Also I have a base class human, and all humans eat so there's a method
eat defined thus (* denotes the method eat)
human *----void (eat& food)
/ \
/ \
vegetarian carnivore
Now the question is how do we work things such that a vegaterian will
never eat meat, in terms of our class design etc. There's probably a
million and one answers but I'd like to get the best one from the
experts on this group
thanks much and have a nice weekend.
GrahamO
the correct answer. The setup is this;
If I have a base class "food" and also two classes "meat" and "veg"
that inherit from food, thus;
food
/ \
/ \
meat veg
Also I have a base class human, and all humans eat so there's a method
eat defined thus (* denotes the method eat)
human *----void (eat& food)
/ \
/ \
vegetarian carnivore
Now the question is how do we work things such that a vegaterian will
never eat meat, in terms of our class design etc. There's probably a
million and one answers but I'd like to get the best one from the
experts on this group
thanks much and have a nice weekend.
GrahamO