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 241165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:43:50+00:00 2026-05-11T20:43:50+00:00

first question here, so hopefully you’ll all go gently on me! I’ve been reading

  • 0

first question here, so hopefully you’ll all go gently on me!

I’ve been reading an awful lot over the past few days about polymorphism, and trying to apply it to what I do in c#, and it seems there are a few different ways to implement it. I hope I’ve gotten a handle on this, but I’d be delighted even if I haven’t for clarification.

From what I can see, I’ve got 3 options:

  1. I can just inherit from a base
    class and use the keyword
    ‘virtual‘ on any methods that I
    want my derived classes to
    override.
  2. I could implement an abstract class with virtual methods
    and do it that way,
  3. I could use an interface?

From what I can see, if I don’t require any implementation logic in the base, then an interface gives me the most flexibility (as I’m then not limiting myself with regards multiple inheritance etc.), but if I require the base to be able to do something on top of whatever the derived classes are doing, then going with either 1 or 2 would be the better solution?

Thanks for any input on this guys – I have read so much this weekend, both on this site and elsewhere, and I think I understand the approaches now, yet I just want to clarify in a language specific way if I’m on the right track. Hopefully also I’ve tagged this correctly.

Cheers,
Terry

  • 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-05-11T20:43:50+00:00Added an answer on May 11, 2026 at 8:43 pm

    An interface offers the most abstraction; you aren’t tied to any specific implementation (useful if the implementation must, for other reasons, have a different base class).

    For true polymorphism, virtual is a must; polymorphism is most commonly associated with type subclassing…

    You can of course mix the two:

    public interface IFoo {
        void Bar();
    }
    class Foo : IFoo {
        public virtual void Bar() {...}
    }
    class Foo2 : Foo {
        public override ...
    } 
    

    abstract is a separate matter; the choice of abstract is really: can it be sensibly defined by the base-class? If there is there no default implementation, it must be abstract.

    A common base-class can be useful when there is a lot of implementation details that are common, and it would be pointless to duplicate purely by interface; but interestingly – if the implementation will never vary per implementation, extension methods provide a useful way of exposing this on an interface (so that each implementation doesn’t have to do it):

    public interface IFoo {
        void Bar();
    }
    public static class FooExtensions {
        // just a silly example...
        public static bool TryBar(this IFoo foo) {
            try {
                 foo.Bar();
                 return true;
            } catch {
                 return false;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.