Implement an interface in an abstract class

Is it possible to implement an interface in an abstract class and change the implemented interface method to abstract?

interface ITest { string GetData(); int ProcessData(); } public abstract class MyAbstract:ITest { public int Process() { // some code } public abstract string GetData(); // Change the implemented method into abstract Is it Possible? } 
+4
source share
1 answer

Yes you can do it. Just add the abstract keyword and remove the implementation. There was obviously a trap. Any class that inherits from your abstract class will have to implement GetData . Depending on how many classes are children of MyAbstract , this can lead to a lot of work and code duplication.

In your case, when this method is declared as an interface that implements MyAbstract , you can simply completely abandon GetData and rely on declaring this function in ITest .

+1
source

Source: https://habr.com/ru/post/1384259/


All Articles