Design Choices
You are designing a class structure for a zoo management system. The system currently has an Animal class with basic attributes like name, age, and weight. You need to decide whether to create a Bird class that inherits from Animal or if Bird should be a separate class with a member variable of type Animal.
Do the same thing for a member variable Wing wings that contains details like wingSpan and wingType.
- Analyze the scenario and decide whether
Birdshould inherit fromAnimalorWing. - Justify your decision based on the principles of object-oriented design.
Hint
- Consider whether a
Birdcan logically be considered anAnimal/aWing. - Think about the attributes and behaviors that would be shared between
Birdand other animals in the system.
Answer
In this scenario, a Bird should inherit from Animal because a bird is a type of animal, and it shares common characteristics such as name, age, and weight. The Wing details can be encapsulated in a separate Wing class that is used as a member variable within Bird.