Inheritance design using Interface + abstract class. Good practice?

后端 未结 5 1661
时光说笑
时光说笑 2021-02-05 18:06

I\'m not really sure how to title this question but basically I have an interface like this:

public interface IFoo
{
    string ToCMD();
}

a co

5条回答
  •  时光取名叫无心
    2021-02-05 18:14

    I am not quite sure if this is what you are looking for but perhaps what you want to do is scrap the interface all together and do this:

    abstract class Base
    {
        public abstract string ToCMD();
    }
    
    abstract class Foo : Base { }
    
    abstract class Bar : Base { }
    

    Hopefully you have other members in the Foo and Bar classes! This will allow you to either restrict your custom collection by Base or just use a plain List.

提交回复
热议问题