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

  • Home
  • SEARCH
  • 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 3244586
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:34:08+00:00 2026-05-17T18:34:08+00:00

I’m going over some design pattern questions and I looked at the definition and

  • 0

I’m going over some design pattern questions and I looked at the definition and examples of the Decorator Pattern in GoF. It says

Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

It gives examples of Decorators which use inheritance which is definitely not dynamic, however.

NetObjectives commits the same error:

http://www.netobjectives.com/PatternRepository/index.php?title=TheDecoratorPattern

The Portland Pattern Repository discussion of the Decorator indicates that there is confusion about what is and is not a decorator

http://c2.com/cgi/wiki?DecoratorPattern

Wikipedia makes some sense of this contradiction by noting that the delegate inside the Decorator should be set at construction time (other DI techniques would also work)

http://en.wikipedia.org/wiki/Decorator_pattern

All examples of the Decorator pattern (in Java or C++) require a static construct either through inheritance or by implementing an interface. The explanation in GoF says that the additional responsibilities are attached dynamically, however. But this is simply wrong.

The comments at PPR talk about dynamic languages that can add methods at runtime, but Java and C++ aren’t dynamic and the explanation of Decorator does not say it is limited to dynamic languages like Groovy and Lisp.

Wouldn’t a correct explanation of Decorator say that in languages that don’t support dynamic method creation both static and dyanmic constructs are involved?

GoF’s explanation is simply wrong as shown by their own examples, or have I misunderstood something?

  • 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-17T18:34:09+00:00Added an answer on May 17, 2026 at 6:34 pm

    It looks like GoF’s explanation is just badly written. Calling Decorator an alternative to subclassing when their examples are subclasses is very confusing.

    GoF says that the decorated object and its Decorators must have conforming interfaces. Apparently this is a requirement of the pattern, and they demonstrate this with inheritance. So there is both a dynamic and static component to their Decorator pattern.

    I could also see how you could invert the pattern and make the Decorator(s) a delegate of the decorated object but this would probably result in a convoluted implementation.

    In a dynamic language like Lisp or Groovy I think you could just merge the decoration logic into the draw() logic of the class itself. The requirement for interface conformance would not be necessary, nor would it be necessary to have separate classes for decorated object and Decorator.

    I’m going to add learning Lisp to my Bucket List so I can see how design patterns change in a dynamic language.

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

Sidebar

Related Questions

No related questions found

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.