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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:36:05+00:00 2026-06-17T14:36:05+00:00

I have 3 interfaces with 2 methods each doing the same job. Interface A

  • 0

I have 3 interfaces with 2 methods each doing the same job.

Interface A
{
   Void M1()
   Void M2()
}

Interface B
{
   Void M1()
   Void M2()
}

Interface C
{
   Void M1()
   Void M2()
}

Now, There are 3 classes implementing each of these interfaces.

Public Class A1:A
{
  Public void M1()
  {

  }
  Public void M2()
  {

  }
}

Public Class B1:B
{
  Public void M1()
  {

  }
  Public void M2()
  {

  }
}

Public Class C1:C
{
  Public void M1()
  {

  }
  Public void M2()
  {

  }
}

Functionality of M1 and M2 is exactly same in 3 classes. Interfaces are a part of library, I cannot change the interface and also cannot declare a new interface.

I want to refactor this code so that this duplication can be removed. I thought of creating a common class containing this functionality and then calling common class from each of these classes.

Please suggest.

  • 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-17T14:36:06+00:00Added an answer on June 17, 2026 at 2:36 pm

    It sounds like you should declare your own interface, and then create an adapter – or possibly multiple adapters. For example:

    public interface IUnified
    {
        void M1();
        void M2();
    }
    
    public class UnifiedAdapter : IUnified
    {
        private Action m1;
        private Action m2;
    
        public UnifiedAdapter(A a)
        {
            m1 = () => a.M1();
            m2 = () => a.M2();
        }
    
        public UnifiedAdapter(B b)
        {
            m1 = () => b.M1();
            m2 = () => b.M2();
        }
    
        public UnifiedAdapter(C c)
        {
            m1 = () => c.M1();
            m2 = () => c.M2();
        }
    
        public M1()
        {
            m1();
        }
    
        public M2()
        {
            m2();
        }
    }
    

    (This uses delegates to avoid having to create multiple adapter classes. The best approach depends on your exact situation.)

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

Sidebar

Related Questions

I have a WCF service and methods are exposed as below: public interface IService
I have an interface (called Subject ) that has the following method: public void
I have different fruit class, all implements the same interface IFruit : public interface
I have an interface, IMessage and a class which have several methods for creating
i have implemented keylistener interface and implemented all the needed methods but when i
alt text http://home.elka.pw.edu.pl/~pkolodzi/Capture.PNG I have created the IAdder interface with two methods: PassA and
I have a class with only class methods (utility stuff), so my interface is
As you know, in a java interface, all methods have to be defined as
I often have to implement some interfaces such as IEnumerable<T> in my code. Each
I have a series of models for my application. Across all these models there

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.