Extension interface patterns

后端 未结 11 2014
失恋的感觉
失恋的感觉 2020-12-14 16:56

The new extensions in .Net 3.5 allow functionality to be split out from interfaces.

For instance in .Net 2.0

public interface IHaveChildren {
    str         


        
11条回答
  •  轮回少年
    2020-12-14 17:03

    Ouch. Please don't extend Interfaces.
    An interface is a clean contract that a class should implement, and your usage of said classes must be restricted to what is in the core Interface for this to work correctly.

    That is why you always declare the interface as the type instead of the actual class.

    IInterface variable = new ImplementingClass();
    

    Right?

    If you really need a contract with some added functionality, abstract classes are your friends.

提交回复
热议问题