Objects without an immediate common parent and polymorphism

Jun 18 2017 2:25 PM
Instructions here:
 
[img]http://i.imgur.com/Nr2o9nt.png[/img]
http://i.imgur.com/Nr2o9nt.png
 
[img]http://i.imgur.com/YwxGjhm.png[/img] 
http://i.imgur.com/YwxGjhm.png
 
Hi, If I understand the question right, the CalculateComplexityScore() method should take either a Cat, Dog or Butterfly object and perform actions on their properties (e.g. on ActionType) depending on wither the object is of Cat, Dog or Butterfly.
 
But Cat, Dog and Butterfly do not have a common immediate parents. They can't be redefined to have one. I have given CatBase, DogBase and Butterfly base a common parent: AnimalBase, but this would allow CalculateComplexityScore to take objects of CatBase, DogBase or ButterflyBase. If you read the instructions, this should not happen.
 
My attempt to solve this was to define an ActionType property as a virtual property in AnimalBase and have Cat, Dog and Butterfly override it but this is still not quite right.

Any help before tomorrow?

Answers (1)