My previous understanding of the decorator pattern was that you inherit Window
with WindowDecorator
, then in the overridden methods, do some additional work before calling the Window
's implementation of said methods. Similar to the following:
public class Window
{
public virtual void Open()
{
// Open the window
}
}
public class LockableWindow // Decorator
{
public virtual void Open()
{
// Unlock the window
base.Open();
}
}
However this essentially hardcodes the decoration, so how would this be refactored to use composition instead of inheritance?