Monday, September 23, 2019

Modeling an Animal Class Hierarchy by Employing UML Diagrams Assignment

Modeling an Animal Class Hierarchy by Employing UML Diagrams - Assignment Example Inheritance is an important principle in object-oriented programming. It not only serves as an organizational technique, but also allows code to be reused between classes that share certain characteristics. It is also known as â€Å"Is A† relationship because the classes down in the inheritance hierarchy are derived from the higher classes. So an object instantiated from a derived class is also a type of the superclass (Dale, Joyce, & Weems, 2006). Generalization and specialization are the two constituents of an inheritance relationship. The base class, from which the child classes are derived from, is supposed to be the more generic class and the child classes with additional members are considered to be the more specialized classes (Thampi, 2009). For example, a dog class can be considered as a sub class of an animal class. In this case the animal class is more generic class and the dog class is the specialized version of the animal class. To construct the animal class hierarchy, we consider the classes Animal, Fish, Mammal, Shark, Herring, Elephant and Rodent. Animal is modeled as the base class from which all the other classes inherit either directly or indirectly. Fish and Mammal classes are the direct child classes derived from the Animal class. Sharks and herring are types of fishes and hence we can derive these classes from the Fish class. Similarly elephants and rodents are both mammals and hence they can be derived from the Mammal class.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.