Created
December 29, 2011 16:38
-
-
Save rbwestmoreland/1534885 to your computer and use it in GitHub Desktop.
Properly Implementing the Decorator Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
/// <summary> | |
/// The object which adds responsibilities to | |
/// a base instance. | |
/// <para>The Decorator pattern is a structural pattern, whose | |
/// purpose is to attach additional responsibilities to | |
/// an object dynamically keeping the same interface. </para> | |
/// </summary> | |
public class BaseDecorator : IBase | |
{ | |
private IBase Instance { get; set; } | |
public BaseDecorator(IBase instance) | |
{ | |
Instance = instance; | |
} | |
public void DoWork() | |
{ | |
//Perform default responsibilities. | |
Instance.DoWork(); | |
// Add responsibilities here. | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
/// <summary> | |
/// The base interface. | |
/// </summary> | |
public interface IBase | |
{ | |
void DoWork(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment