Talk:Decorator pattern

message: My goodness. If I don't get to NPOVing/encyclopedicafying the "taco" example, could someone, please? Dysprosia 10:31, 4 Nov 2003 (UTC)
replies: text: The latest PNA cycle improved a lot, but there's still a big gap between here and goodness ("objects can have attributes that change something about them" sounds like something from a philosophy article). Let me work it over a bit... JRM
OK, I've revamped it, hopefully clarifying it (and removing the absurd "taco" example altogether). I've also removed links to bean pattern (much too specific reference to Enterprise Java Beans) and self joining data (I've never even heard of this and I doesn't Google in any relevant way—if this is not just another fifteen-minutes buzzword and someone else has, please do write an article about it and (if it's related) reinstate the link). 
I'm still not perfectly happy with what I've written (it's still not accessible enough to the Ignorant Outside World), but this is simply because I'm not a writer (and don't have access to Design Patterns at present). You there! Improve it! I don't know where you're from, but here on Wikipedia, we collaborate! :-) JRM 14:15, 2004 Nov 16 (UTC)
Ech, I just saw proxy pattern. We have a long way ahead of us. Anyone feel like a new WikiProject? :-) JRM 14:15, 2004 Nov 16 (UTC)
OK, I've added the section headings suggested by the Gang of Four on the Design pattern (computer science) page, and rearranged the existing content under these headings. However, we still need additional content. AmunRa84, 14:07, 2005 Jan 9 (UTC)
The layout looks fine so I'm removing the "wikify" tag. If the article still neads a lot of work, we can put "cleanup" instead? Jeeves 02:26, 9 Jun 2005 (UTC)
thread_title:  Tags 

message: Hi guys, hope this is the right place for a comment (my first on Wikipedia): the Java code provided may be better off with an explicit "extend Window" in the decorator class declarations. The text above the code mentions that it is a requirement, but the snippet does not have it. Hope this helps. Taibr 03:39, 25 January 2006 (UTC)
replies: text: I think the text may be incorrect. You can see that myWindow is a private variable of the Window class so it doesn't necessarily need to be a subclass. It is this variable which is to become decorated. As another example, one could argue that a beach ball class is a decoration on a sphere class but BeachBall doesn't necessarily need to extend Sphere (nor vice versa), just use a sphere and apply it's own "proprietory" attributes. There probably should be a Window interface, a new class that implements Window, and the Vertical/Horizontal scroller classes that implements Window and uses a variable which is of type {the new class}. Hopefully we can get more comments here.--Will2k 04:51, 25 January 2006 (UTC)

text: I am not an expert, but I think you're right: the original class and its decorated version should share a common superclass. This is required because you want to dynamically use (and cascade) decorators at run-time, yet having the resulting decorated class still of the same (super)type as the original class. So, you're right that your (concrete) decorator should not necessarily extend Window, so long Window and itself have a common superclass, which defines the utility methods you want to use. From what I see in the literature, the superclass "S" can be either abstract or an interface (in Java); and the concrete decorator may inherit an abstract decorator which is the one extending or implementing "S". The [second reference at the bottom of the page] has nice diagrams. But you're also very right on this: more comments would be good :) --Taibr 05:07, 27 January 2006 (UTC)
thread_title:  Explicit implementation? 

message: What benefit does this class provide over having the decorators implement Window directly? (honestly trying to learn here)
:I was really helped with the example, and indeed, with all respect, your example replacement shows precisely that indeed you didn't get the point. You are creating a local new data
member "private Window windowToBeDecorated;". With this approach, the Horizontal will also contain such a field and
so for the Horizontal-and-Vertical window you will now do what? Mayb eyou make a subclass of one of those and so the number of classes explodes, and maybe you will again make a local field so store 2 times the same field ?  — Preceding unsigned comment added by Renaat Truijen (talk • contribs) 09:39, 12 November 2020 (UTC)
thread_title:  Java example's WindowDecorator class is unnecessary 

message: The diagram should show the operation() in the decorator tree instead of the doStuff() method.
Oldani 17:30, 20 Mar 2007 (UTC)
thread_title:  Mistake in the diagram 

message: I think WindowDecorator is missing an "implements" link to Window: the corresponding Java code states "abstract class WindowDecorator implements Window", and the general example above shows the same relationship between Decorator and Component. Ma82 (talk) 13:02, 2 June 2008 (UTC)
thread_title:  Mistake in the diagram of the example 

message: This page seems to have started down an all-too-common path of turning into a repository for a multitude of redundant examples in numerous languages.  We need to pick the one clearest example, be it in pseudocode or some actual language, and get rid of the others.  --Doradus (talk) 19:49, 9 January 2009 (UTC)
replies: text: Ok, I've decided to be bold and delete all but the Python example.  --Doradus (talk) 13:52, 14 March 2009 (UTC)
replies: text: The Python example should go as well. It uses a language mechanism with the same superficial behaviour and the same name, but it's not a precise example of the design pattern in question. Quoted from Python_syntax_and_semantics#Decorators: "Despite the name, Python decorators are not an implementation of the decorator pattern." 195.169.128.3 (talk) 08:38, 29 July 2009 (UTC)
thread_title:  Too many code examples 

message: I think the introduction is not generic enough, i.e. uses too much implementation and language specific terms. Talking about delegating the method calls to the decorated object would be better. Also I don't really like the use of pointers, using reference might be better (I know, that in some languages, like C&C++ they both exist don't mean the same). Or just broadly describing it as the decorator delegating to the decorated object, period. The third thing is that the decorator doesn't have to extend the decorated object, it just has to have the same interface. This is clearly shown e.g. java example (not to talk about the dynamic language ones), where the WindowDecorator doesn't do anything but holds a reference to the decorated object. 
A decorator base class can be useful for implementing decorators for complicated interfaces if it contained a default delegating implementation for all the methods. But it's a different question I think (and as I said in the java example the abstract base doesn't have any behaviour...) Atleta.hu (talk) 23:42, 9 March 2009 (UTC)
thread_title:  Genericity of introduction 

message: I'm not sure what protocol is here, but the information in the link "Sample Chapter "C# Design Patterns: The Decorator Pattern" (C#) by James W. Cooper" appears to be misleadingly wrong.  He ends up creating a simple class inheritance rather than a decorator.  If someone could verify and then remove the link? 146.12.3.3 (talk) 19:26, 23 April 2009 (UTC)
replies: text: I just read it. It's not clear to me if it is wrong or just a bad/incomplete explanation. I'll remove the link. In the future, be bold!. —Ben FrantzDale (talk) 22:21, 25 April 2009 (UTC)
thread_title:  External Links 

message: According the gang of four, the UML diagram on this page describes the strategy pattern not the decorator pattern.  —Preceding unsigned comment added by 193.248.173.87 (talk) 00:13, 29 May 2010 (UTC)
thread_title:  Wrong UML diagram 

message: Even for Wikipedia standards, it can't get more confusing than this: 
"Not to be confused with the concept of "decorators" in Python.
This is an example using Python's concept of "decorators," but not using the Decorator Pattern, since this is modifying the class directly not an instance of the class."
What?
87.151.238.174 (talk) 12:14, 6 October 2010 (UTC)
replies: text: Good point. I fixed it. —Ben FrantzDale (talk) 11:46, 7 October 2010 (UTC)
thread_title:  Python example description 

message: Shouldn't WindowDecorator include a getDescription() method?
206.47.231.164 (talk) 18:00, 20 December 2010 (UTC)
thread_title:  Incomplete interface 

message: One of the key values of the decorator pattern stated, was that decoration could be done during the run.  However, both Java examples require the decorated object to be passed to the constructor of the decorator.  Hence, decoration can only be done statically in the code.  It cannot be done during the run.  
But it's not just the Java examples, by the UML diagram that encodes this static-only restriction. Inconsistent.
To make decoration possible during the run, the linkage would have to be something along the lines of a linked-list, such as in the chain-of-responsibility pattern..  except, each link in the chain is a decorator, and the chain starts with the decorated object.  As control moves down the chain, each decorator receives an object from up-chain, and adds its own decoration.  For the scrollbar example, each would receive, for example, an object that represents the state of a canvas..  what area remains free to be painted by the decorator..  and perhaps a means of connecting decorations like scrollbars to the text-area that they control..  the current example seems a bit bogus, actually, because information and control has to be exchanged between the decorators and the decorated window..  a scrollbar doesn't just paint itself!  It has to cause the painter of the text area to re-paint in a particular way..  so it has to be connected to the painter of the text area in an intimate way..
Seanhalle (talk) 18:57, 2 January 2013 (UTC)
thread_title:  Inconsistent: intro says decorate at run time, examples are static decoration 

message: Wouldn't it be more correct to change the UML diagram instead of the example Java code to get examples that are according to the UML diagram on top of the page?
I think, now both the UML diagram and the two examples ("coffee making scenario" and "window/scrolling scenario") are wrong.
Michael (--92.231.222.37 (talk) 07:37, 22 February 2013 (UTC)
thread_title:  14:13, 18 February 2013: not according to uml diagram on top of the page 

message: Is there a particular reason why the Java example with Coffee doesn't use delegation in its concrete decorator classes? Why should Milk be an instance of coffee and be tied to coffee me</ref>chanisms? Why doesn't this example follow the one preceding it with Windows where Milk should have a Coffee member, and delegate & override the coffee functionality to its member?
--Azadi { (talk) 04:17, 12 October 2013 (UTC)
thread_title: Delegation in the Java example

message: Hello fellow Wikipedians,
I have just modified  on Decorator pattern. Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:
*Added archive https://web.archive.org/web/20150707165957/http://sam-burns.co.uk/57/how-to-implement-a-decorator-pattern/ to http://sam-burns.co.uk/57/how-to-implement-a-decorator-pattern/
When you have finished reviewing my changes, please set the checked parameter below to true or failed to let others know (documentation at ).
Cheers.—InternetArchiveBot (Report bug) 00:30, 10 December 2016 (UTC)
thread_title:  External links modified