The Decorator Pattern & Extension Methods in c#

前端 未结 5 2040
情歌与酒
情歌与酒 2021-02-04 01:59

Before going to describe my problem first,I would like to define definitions of Decorator and Extension method Decorator

Attach additiona

5条回答
  •  半阙折子戏
    2021-02-04 02:35

    A extension method is really just syntactic sugar for calling a static method.

    While with a decorator you could actually change the behaviour of your decorated class, a extension method could only alter properties or call methods on your class, just like an "ordinary" static method.

    Decorator pattern is actually definied as using a wrapper to alter behaviour, which a extension method clearly doesn't do.

提交回复
热议问题