none
Interfaces in c sharp RRS feed

  • Question

  • HI all,

    In c sharp, is it need to override all the abstract methods of an interface? Or can we override only required abstract methods?

    Wednesday, April 27, 2011 3:05 AM

Answers

  • If you want implement only required methods then implement it in a super class with a dummy implementation which throws not implemented exception. In the derived clases of the super class you  can implement the required methods. This is a way but not good design. Instead divide the interface and implement only desired interface. Interfaces offer multiple contracts for a single object, so let the contacts focused on single responsibility and separate each responsibility with separate interface.

     

    Good luck

    • Marked as answer by Creative_Pro Wednesday, April 27, 2011 4:00 AM
    Wednesday, April 27, 2011 3:45 AM

All replies

  • If you want implement only required methods then implement it in a super class with a dummy implementation which throws not implemented exception. In the derived clases of the super class you  can implement the required methods. This is a way but not good design. Instead divide the interface and implement only desired interface. Interfaces offer multiple contracts for a single object, so let the contacts focused on single responsibility and separate each responsibility with separate interface.

     

    Good luck

    • Marked as answer by Creative_Pro Wednesday, April 27, 2011 4:00 AM
    Wednesday, April 27, 2011 3:45 AM
  • Always Remember If you declared a method as abstract class then u must required to implement it into child class,if u not implement abstract method of base class into child class then at the compilation time it gives u an error that u not implement abstract method.

    S.K Nayak

    Thursday, June 5, 2014 6:27 PM