locked
Design Pattern - Extension Method RRS feed

  • Question

  • Whether extension method is Microsoft's implementation of Decorator Pattern?!
    Thursday, September 12, 2013 10:39 AM

Answers

  • Hi,

    Extension Method and Decorator Pattern look like very similar. But I don’t think Extension Method is the implementation of Decorator Pattern. Because Extension Method has four limited features.

    1. Extension Method must be contained in a static class.
    2. Extension Method must be a static method.
    3. Extension Method’s first parameter must has “this” keyword to represents the instance to reference itself.
    4. When use Extension Method, you must import namespace first.

    Obviously, the Decorator Pattern has not have this limitation.

    Best Regards,

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Friday, September 13, 2013 10:06 AM

All replies

  • yes, extension methods are Microsoft's implementation of Decorator pattern.

    One good question is equivalent to ten best answers.

    Thursday, September 12, 2013 11:07 AM
  • I think Decorator Pattern is part of the Extension method but not the same.
    Thursday, September 12, 2013 11:39 AM
  • Hi,

    Extension Method and Decorator Pattern look like very similar. But I don’t think Extension Method is the implementation of Decorator Pattern. Because Extension Method has four limited features.

    1. Extension Method must be contained in a static class.
    2. Extension Method must be a static method.
    3. Extension Method’s first parameter must has “this” keyword to represents the instance to reference itself.
    4. When use Extension Method, you must import namespace first.

    Obviously, the Decorator Pattern has not have this limitation.

    Best Regards,

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Friday, September 13, 2013 10:06 AM
  • Thanks indeed for your response.
    Monday, September 16, 2013 6:13 AM