Inheritance design using Interface + abstract class. Good practice?

后端 未结 5 1649
时光说笑
时光说笑 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:28

    Well, that's what the where keyword is for. You probably need to evaluate your object model to make sure that the depth of your inheritance is necessary. Deep inheritance hierarchies tend to complicate projects and are generally a red flag, but it depends on the situation.

    Usually, you don't need the abstract class to pull off the functionality you're talking about with the lists, and interfaces are the 'preferred' method for specifying type restrictions. I'd only use the abstract version of your class if there is common functionality you want to encapsulate.

    Short answer: make sure you're not going inheritance crazy.

    Hope that helps!

提交回复
热议问题