|
Can anybody explain why the name "Decorator" was chosen for the functionality conveyed by the Decorator design pattern?
I've always found that name fairly misleading, because decorator and marking interface sound very similar to me in their purpose. However...
Started by Uri on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
I believe that the origin of the term comes from the example use of DECORATOR (and presumably the application from....
A decorator into the base class.
Hey, leave it to geeks to make up names.
The object with the new functionality.
|
|
I'm excited to see the latest version of the decorator python module (3.0). It looks a lot cleaner (e.g. the syntax is more sugary than ever) than previous iterations.
However, it seems to have lousy support (e.g. "sour" syntax, to horribly stretch the...
Started by YGA on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
(Anything can be solved by another level of indirection...)
from decorator import decorator def substitute_args(arg_sub_dict): @decorator def wrapper(fun, arg....
In this case, you need to make your function return the decorator.
|
|
This question was asked already here , but rather than answering the specific question, descriptions of how the decorator pattern works were given instead. I'd like to ask it again because the answer is not immediately evident to me just by reading how...
Started by es11 on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Using the abstract decorator implementation reduces....
Using decorators based on the abstract decorator class, you how this explodes as the number of possible combinations increases.
Your Beverage with milk and nutmeg.
|
Ask your Facebook Friends
|
I am going over my design patterns, and one pattern I have yet to seriously use in my coding is the Decorator Pattern.
I understand the pattern, but what I would love to know are some good concrete examples of times in the real world that the decorator...
Started by Alex Baranosky on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
I've recently ....
Zend Framework uses the decorator for form elements
Some more info: http://framework.zend.com/manual/en/zend.form.decorators.html
The decorator pattern is used a lot with streams: you can wrap compression.
|
|
I just recently really truly groked dependency injection and the wonder of the Decorator design pattern and am using it all over the place.
As wonderful as it is however, one thing that I've been having difficulty with is naming my decorator classes so...
Started by George Mauer on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Name the decorator class/function after what it does the decorator....
Then it's clearer and easier to include the pattern name in the class, in this case using Decorator as a suffix this belongs in documentation if anywhere.
|
|
I'm just reading up on the Chain of Responsibility pattern and I'm having trouble imagining a scenario when I would prefer its use over that of decorator .
What do you think? Does CoR have a niche use?
Started by George Mauer on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Filters may or maynot handle a specific request but adding a decorator....
Not in a general enhancement form as the decorator does.
Well I can think of 2.
I'd say that a Chain of Responsibility is a particular form of Decorator .
|
|
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...
Started by Neil Barnwell on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
In order to use it most effectively } } public class LockableWindow // Decorator....
Adding buffering to a stream) in a way that's transparent to the caller .
The point of the Decorator pattern is to enhance an object with some functionality (e.g.
|
|
I have been trying to create a decorator that can be used with both functions and methods in python. This on it's own is not that hard, but when creating a decorator that takes arguments, it seems to be.
class methods(object): def __init__(self, *_methods...
Started by Matthew Schinckel on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Maybe you can better explain one toy use you'd want for your decorator, so we can__ to use your decorator on the Bound Method, you could pass a flag telling it if it's being used to use the same ....
Thereof).
|
|
I'd like to create a Python decorator that can be used either with parameters:
@redirect_output("somewhere.log") def foo(): ....
or without them (for instance to redirect the output to stderr by default):
@redirect_output def foo(): ....
Is that at all...
Started by gooli on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
If you were using Python 3.0 you could use keyword only arguments lambda f: decorator(arg, f)
This should be ok unless you wish to use a function as an argument to your(foo=bar, baz....
Scenarios in your decorator code.
|
|
Is there any way of writing a decorator such that the following would work?
assert 'z' not in globals() @my_decorator def func(x, y): print z
EDIT: moved from anwser
In answer to hop's "why?": syntax sugar / DRY.
It's not about caching, it's about calculating...
Started by Toby White on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
Something like:
import types def my_decorator(fn): def decorated(*args,**kw): my_globals={} my_globals) return call_fn(*args,**kw) return decorated @my_decorator def func(x, y): print z func(0,1 declare z as global....
Temporarily.
|