Interface and base class mix, the right way to implement this

Posted by Lerxst on Stack Overflow See other posts from Stack Overflow or by Lerxst
Published on 2010-06-08T16:27:59Z Indexed on 2010/06/08 16:32 UTC
Read the original article Hit count: 293

I have some user controls which I want to specify properties and methods for.

They inherit from a base class, because they all have properties such as "Foo" and "Bar", and the reason I used a base class is so that I dont have to manually implement all of these properties in each derived class.

However, I want to have a method that is only in the derived classes, not in the base class, as the base class doesn't know how to "do" the method, so I am thinking of using an interface for this. If i put it in the base class, I have to define some body to return a value (which would be invalid), and always make sure that the overriding method is not calling the base. method

Is the right way to go about this to use both the base class and an interface to expose the method? It seems very round-about, but every way i think about doing it seems wrong...

Let me know if the question is not clear, it's probably a dumb question but I want to do this right.

© Stack Overflow or respective owner

Related posts about c#

Related posts about best-practices