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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:26:09+00:00 2026-05-12T14:26:09+00:00

Imagine the following code: MyService myService = new MyService(); myService.Start(); myService.DoStuff(); The MyService class

  • 0

Imagine the following code:

MyService myService = new MyService();
myService.Start();
myService.DoStuff();

The MyService class looks like this:

public class MyService : ClientBase, IMyService
{
...
}

Now I wanted to change the existing code to call this class by using its interface:

IMyService myService = GetMyService();
myService.Start();
myService.DoStuff();

Looks better, but now I get an error on the line containing myService.Start();, since this is an implementation inherited from the ClientBase base class.

What should I do now? Extend the IMyService interface and include the ClientBase interface? That’s the only solution I can think of now, but I don’t think it’s very elegant…

EDIT: The ClientBase class is the one from System.ServiceModel so I can’t change anything about this.

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

    There is nothing wrong with interface inheritance…

    public class ClientBase: IClientBase
    {
        public ClientBase()
        {
        }
    
        public void Start()
        {
        }  
    }
    
    public interface IClientBase
    {
        void Start();
    }
    
    ...
    
    public class MyService: ClientBase, IClientBase, IMyService
    {
        public MyService()
        {
        }
    
        public void DoStuff()
        {
        }
    }
    
    public interface IMyService: IClientBase
    {
        void DoStuff();
    }
    

    Then you should be allowed to use your existing code:

    IMyService service = new MyService();
    service.Start();
    service.DoStuff();
    

    An alternative solution would be to make your MyService class implement IClientBase and then just do a cast:

    MyService service = new MyService();
    (service as IClientBase).Start();
    (service as IMyService).DoStuff();
    

    However, I think youl agree the first solution is much better.

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

Sidebar

Related Questions

Imagine the following code, written in C#: public class Provider<T> { T GetValue(); //
Imagine the following code: class foreach_convert { public static void method2() { List<IComparable> x
Imagine that i have the following code: <a:repeat value=#{bean.getList()} var=x > <li class=la> <span>
Imagine you have two views with code like the following: controller_a/a.html.erb <%= content_tag(:div) do
Imagine the following code: class SimpleLetter def values (a .. z).to_a end def ===(other)
Imagine the following simple code: public void F<T>(IList<T> values) where T : struct {
Imagine the following REBOL code: foo: context [bar: 3] I now have a context
I have the following code in my header file: class Factovisors { public: Factovisors(std::istream&
Imagine I have the following code: class A { [UsefulAttribute(foo)] B var1; [UsefulAttribute(bar)] B
imagine I type the following code into the interpreter: var1 = 'zuuzuu' now suppose

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.