Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9197471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:04:47+00:00 2026-06-17T22:04:47+00:00

I read that inheritance should be used only if you want to use the

  • 0

I read that inheritance should be used only if you want to use the overriding facility. Interfaces and composition should be used if you only use inheritance for code sharing. Have a look at the code below:

Public Class Animal
    Public Overridable Sub Eat()
        MsgBox("Animal Eat no arguement")
    End Sub
End Class

Public Class Horse
    Inherits Animal
    Public Overrides Sub Eat()
        MsgBox("Horse Eat no arguement")
    End Sub
End Class

Horse inherits from Animal and overrides Eat. This is a valid use of inheritance based on what I read. Now say you add a Cat class and a Dog class that inherit from animnal. Now say that Horse; Cat and Dog use the Eat function from the Animal class (instead of overriding it) then this is an invalid use of inheritance based on what I read (interfaces shouod be used). Surely if you use interfaces i.e. IEatable to implement the Eat interface then Eat has to be written in every class, which minimizes reuseability and maintainability. What am I missing here?

Update
After reading the responses I believe I can do something like this:

 Public Class Animal
    Public Overridable Sub Eat()
        MsgBox("Animal Eat no arguement")
    End Sub
End Class

Public Class Fish
    Inherits Animal
    Implements ISwim
    Private s1 As New Swim
    Public Sub Swim() Implements ISwim.Swim
        s1.Swim()
    End Sub
End Class

Public Class Shark
    Inherits Animal
    Implements ISwim
    Private s1 As New Swim
    Public Sub Swim() Implements ISwim.Swim
        s1.Swim()
    End Sub
End Class

Public Class Elephant

End Class

Public Class Swim
    Public Sub Swim()
        MsgBox("Animal can swim")
    End Sub
End Class

Public Interface ISwim
    Sub Swim()
End Interface

In the above code, two of the three animals implement ISwim and use composition to provide an implementation of Swim. Is this a valid approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:04:50+00:00Added an answer on June 17, 2026 at 10:04 pm

    You would use inheritance for the implementation of Eat if you can use the same code for all, or some, of the classes. If you need different implementations for some classes, you can make it virtual and use the implementation from Animal in any class that doesn’t specifically have a different implementation.

    You would use an interface if you have different implementations for all classes, or if you want to add the ability to only some of the clases. The ISwim interface would for example only be implemented by some animals.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read that Windows wp8 allows native code. So how then have ports such
I'm writing some serialization/deserialization code in Python that will read/write an inheritance hierarchy from
I have read When should I choose inheritance over an interface when designing C#
Multiple Inheritance in ActionScript 3? Is it possible? I have read somewhere that it
I have read in many textbooks that In Ruby,a class can only be a
I read about an inheritance feature in PostgreSQL that seemed pretty neat. Unfortunately I
I read that WCF service throttling enqueues requests internally without any additional code. Is
What i'm tring to do is this. I have a Inheritance tree that looks
I have read from literature that a variable shouldn't be declared protected just so
Here is the problem I want to use a constructor that will simplify image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.