Sign in to follow this  

Help with Inheritance, Polymorphism

This topic is 4592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I would appriciate if someone could help me with this, plz bare with me if the explination is a bit off. Scenario: A zoo with the following animals in it, Crocodile, monkey , snake and they all have one thing in common regardles of what type of animal they are, they all eat a certain amount of food , weight etc... . . 1. What objects are involved here(What are the objects of this scenario)? 2. How can reuse my code? 3. Do i use copy constructors to make copy's of the objects || Do i Inherit? I know i am all over the place plz help any1. Thanks in advance Bhangie

Share this post


Link to post
Share on other sites
1. An object for each animal, every one of them implements the base object that has all the properties you mention (food consumption etc.)
2. Instead of writing code to handle each animal type, you will write code to hand any kind of animal, regardless of its type.
3. Animals inherit from the base (abstract) class. Copy constructors are always useful to have, but they play no role here.

Note: if the only difference between the animals is their weight, food consumption, name, then inheritance is not a good idea. Inheritance is only useful when each animal has a property that other animals don't have. Otherwise, create an "animal" object with a fixed set of properties, and use it.

Share this post


Link to post
Share on other sites

This topic is 4592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this