Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 221413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:01:52+00:00 2026-05-11T19:01:52+00:00

My previous understanding of the decorator pattern was that you inherit Window with WindowDecorator

  • 0

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 : Window // 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:01:52+00:00Added an answer on May 11, 2026 at 7:01 pm

    Sorry, my C# is a a bit (OK, very) rusty, so there may be a few syntax errors, but the basic idea is right.

    public interface IWindow
    {
        void Open();
    }
    
    public class Window : IWindow
    {
        public virtual void Open()
        {
            // Open the window
        }
    }
    
    public class LockableWindow : IWindow
    {
        private IWindow _wrappedWindow;
    
        public LockableWindow(IWindow wrappedWindow)
        {
            _wrappedWindow = wrappedWindow;
        }
    
        public virtual void Open()
        {
            // TODO Unlock window if necessary
            _wrappedWindow.open();
        }
    }
    

    The key thing to notice is the new IWindow interface; that’s what allows you to keep using polymorphism.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to have some difficulty understanding the way these jQuery selectors work. Say
In previous versions of Excel there was a registry entry that you could create
From previous post, I learnt that for there are two ways, at least, to
From previous experience I had been under the impression that it's perfectly legal (though
In previous question of mine, someone had meantioned that using Semaphores were expensive in
In previous versions of Xcode creating a window-based, universal application would populate the project
In my previous understanding, for a web site, only login user of a web
My understanding is that C++ allows static const members to be defined inside a
I have a strange problem that probably stems from lack of understanding of how
My limited understanding of the Fourier transform is that you should be able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.