Extension interface patterns

后端 未结 11 2013
失恋的感觉
失恋的感觉 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:08

    Extension methods should be used as just that: extensions. Any crucial structure/design related code or non-trivial operation should be put in an object that is composed into/inherited from a class or interface.

    Once another object tries to use the extended one, they won't see the extensions and might have to reimplement/re-reference them again.

    The traditional wisdom is that Extension methods should only be used for:

    • utility classes, as Vaibhav mentioned
    • extending sealed 3rd party APIs

提交回复
热议问题