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

  • Home
  • SEARCH
  • 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 1021487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:19:06+00:00 2026-05-16T11:19:06+00:00

I have a design problem I’d like to solve. I have an interface, lets

  • 0

I have a design problem I’d like to solve.
I have an interface, lets call it IProtocol, which is implemented by two separate classes. We’re looking at over 600 lines of code here. The vast majority of the stuff they do is the same, except for some specific areas, like DiffStuff();

Current structure is something like this:

public class Protocol1 : IProtocol
{
  MyInterfaceMethod1()
  {
     Same1();
     DiffStuff();
     Same2();
  }
}

And

public class Protocol2 : IProtocol
{
  MyInterfaceMethod1()
  {
     Same1();
     Same2();
  }
}

I’m concerned with having copy-paste errors and the classic problem of code duplication if I keep the two protocols separate. We’re talking about a full 600 lines of code each, not some simple methods.

I’m considering changing the implementation of Protocol1 to inherit from protocol2, like this (Protocol2 would mostly stay the same, except I’d have to wrap Same1() and Same2() into private methods.)

public class Protocol1 : Protocol2
{
  void Same1()
  {
     base.Same1();
  }

  void Same2()
  {
     base.Same2();
  }

  MyInterfaceMethod1()
  {
     Same1();
     DiffStuff();
     Same2();
  }
}  

Is this the right way to go about dealing with this problem?

Edit:
Many people helped me with this question, thanks for the clear understanding. In my case, the two objects are not of the same type, even though much of their implementation is shared, so I went with Bobby’s suggestion to use abstract base class, creating small methods to encapsulate changes between the classes. Additional Thanks to:

  • jloubert
  • Hans Passant
  • Jeff Sternal
  • 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-16T11:19:06+00:00Added an answer on May 16, 2026 at 11:19 am
        /// <summary>
        /// IProtocol interface
        /// </summary>
        public interface IProtocol
        {
            void MyInterfaceMethod1();
            void Same1();
            void Same2();
        }
    

    then…

    public abstract class ProtocolBase : IProtocol
    {
        #region IProtocol Members
    
        public void MyInterfaceMethod1()
        {
            // Implementation elided...
        }
    
        public void Same1()
        {
            // Implementation elided...
        }
    
        public void Same2()
        {
            // Implementation elided...
        }
    
        public abstract void DiffStuff();
    
        #endregion
    }
    

    finally…

    public sealed class Protocol1 : ProtocolBase
    {
        public override void DiffStuff()
        {
            // Implementation elided...
        }
    }
    
    public sealed class Protocol2 : ProtocolBase
    {
        public override void DiffStuff()
        {
            // Implementation elided...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 503k
  • Answers 503k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This turned out to be an issue with the version… May 16, 2026 at 2:56 pm
  • Editorial Team
    Editorial Team added an answer How about using tkinter? from Tkinter import Tk # from… May 16, 2026 at 2:56 pm
  • Editorial Team
    Editorial Team added an answer Your Event.hbm.xml says: <set name="attendees" cascade="all"> <key column="attendeeId" /> <one-to-many… May 16, 2026 at 2:56 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a design problem which I would like some input on. Here are
I have a design problem. I have two data objects which are instances of
I saw a tool which can tell you if you have design problem in
We are developing an enterprise-size accounting system and we have logical design problem which
I have an interesting design problem and I was hoping you all could make
I have a database design problem , where the database object's properties are not
Hello guys, I have a general design problem with iPhone application. I want to
I'm currently coding my design portfolio and have encountered a problem with the layout.
I'm dealing with a design problem that I'm sure has a simple answer and/or
Think Design: I have many applications that share the same user database! Other tables

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.