Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an abstract class that implements multiple interfaces in c#

I'd like to create an abstract class in c#, that "inherits" from different interfaces, but leaves the concrete implementation to the subclass. The compiler however complains, that the class doesnt implement the methods specified in the interfaces. I'm used to Java where this always worked, so I'm not sure how it is supposed to work in c#. Anyway, this is my code:

 public abstract class MyClass : IDisposable, IPartImportsSatisfiedNotification
 {
   private string name; 
   public MyClass(string name)
   {
       this.name = name; 
   }
 }
like image 975
Pedro Avatar asked Oct 22 '11 20:10

Pedro


1 Answers

Add abstract methods:

    public interface IPartImportsSatisfiedNotification
    {
        void SomeMethod();
    }

    public abstract class MyClass : IDisposable, IPartImportsSatisfiedNotification
    {
        private string name;
        public MyClass(string name)
        {
            this.name = name;
        }

        public abstract void SomeMethod();

        public abstract void Dispose();
    }

    public class SubClass : MyClass
    {
        public SubClass(string someString) : base(someString)
        {

        }

        public override void SomeMethod()
        {
            throw new NotImplementedException();
        }

        public override void Dispose()
        {
            throw new NotImplementedException();
        }
    }
like image 131
Acaz Souza Avatar answered Sep 22 '22 22:09

Acaz Souza