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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:00:07+00:00 2026-05-28T14:00:07+00:00

I have a C# interface, and a concrete class that implements that interface. I

  • 0

I have a C# interface, and a concrete class that implements that interface. I now want to create another class that implements that interface. Simple enough.

However, most methods will be exactly the same in the classes, and only a couple of methods will actually change.

I don’t want to duplicate all of the logic in my 2nd class that is contained in my first.

How do I create the 2nd class, and use the logic in my first class except for the extra stuff?

My interface is called IEventRepository, and my 1st class is called BaseEvents. I now want to create a new class called FooBarEvents.

My class definition for FooBarEvents is:

public class FooBarEvents : BaseEvents, IEventRepository

My intention was to then use the return base.Method() in each method that duplicates the code.

I’m assuming this isn’t correct?

  • 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-28T14:00:08+00:00Added an answer on May 28, 2026 at 2:00 pm

    FooBarEvents should only need to inherit from BaseEvents, not also implement IEventRepository, as BaseEvents already implements the interface. If you need to change the behavior of some IEventRepository methods in FooBarEvents, just override those methods.

    Edit: some examples

    interface IEventRepository
    {
       void CommonMethodA();
       void CommonMethodB();
       void ImplentationSpecificMethod();
    }
    
    abstract class BaseEvents : IEventRepository
    {
       public void CommonMethodA()
       { ... }
    
       public virtual void CommonMethodB()
       { ... }
    
       public abstract void ImplementationSpecificMethod();
    
       public void BaseEventsMethod()
       { ... }
    
       public void BaseEventsMethod2()
       { ... }
    }
    
    class FooBarEvents : BaseEvents
    {
       public override void CommonMethodB()
       { 
          // now FooBarEvents has a different implementation of this method than BaseEvents
       }
    
       public override void ImplementationSpecificMethod()
       { 
          // this must be implemented
       }
    
       public new void BaseEventsMethod2()
       { 
          // this hides the implementation that BaseEvents uses
       }
    
       public void FooBarEventsMethod()
       { 
          // no overriding necessary
       }
    }
    
    // all valid calls, assuming myFooBarEvents is instantiated correctly
    myFooBarEvents.CommonMethodA()
    myFooBarEvents.CommonMethodB()
    myFooBarEvents.BaseEventsMethod();
    myFooBarEvents.BaseEventsMethod2();
    myFooBarEvents.FooBarEventsMethod();
    myFooBarEvents.ImplementationSpecificMethod();
    
    // use the contract thusly:
    void DoSomethingWithAnEventRepository(BaseEvents events)
    { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a concrete class A that extends BaseA and implements InterfaceA. I want
I have one main interface and an abstract class implementing all derivable methods (that
I have the following interface and abstract class that implements it: interface Walk {
I have an interface Producer<T> and a concrete FooProducer that implements Producer<Foo> . Binding
I have an interface that I have defined in C++ which now needs to
If I have interface IFoo, and have several classes that implement it, what is
Suppose we have: interface Foo { bool Func(int x); } class Bar: Foo {
Lets say you have interface definition. That interface can be Operation . Then you
Have a interface class abc { public: virtual int foo() = 0; ... }
I have an Interface called IStep that can do some computation (See Execution in

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.