Design class for given UML Diagram

Problem statement: For given UML diagram we have to write Classes. This type of question is asked in technical interview to test the basic understanding of UML.

In below UML Diagram, Animal class has been extended/Derived from the Tiger base class.

Answer: Given UML diagram is wrong as it does not follow the “IS-A” relationship in inheritance.

Above UML states that “Animal IS-A Tiger” which is wrong. Correct form is
“Tiger IS-A Animal”, Hence, Tiger class should be derived from Animal class not Animal from a Tiger.

This is the correct UML Diagram.

Note: Interviewer expectation is to just correct the UML, Not to write a class.

NOTES

Further examples “Cat IS-A Animal”, “Dog IS-A Animal” and “Camel IS-A Animal”, so, all Cat, Dog, Tiger and Camel should be derived from Animal class.

Related Posts