|
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):
A decorator of DECORATOR (and presumably the application from which DECORATOR derives its name) lies.
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 this to just ....
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
|
Why can decorator not decorate a staticmethod or a classmethod?
from decorator import decorator @decorator def print_function_name(function, *args): print '%s was called.' % function.func_name return function(*args) class My_class(object): @print_function...
Answer Snippets (Read the full thread at stackoverflow):
From decorator import decorator @decorator def print_function_name(function, *args): print '%s was called.
|
|
I'm implementing a decorator pattern in Javascript.
I've seen the example here in Wikipedia
// Class to be decorated function Coffee() { this.cost = function() { return 1; }; } // Decorator A function Milk(coffee) { this.cost = function() { return coffee...
Started by leeand00 on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
I went back and re-read the Decorator Pattern part of my design patterns book and found:
"The decorator....
The decorator is supposed to change the way an object behaves, how it does the order Okay found the answer.
It does not matter.
|
|
Hi,
I have been looking at the decorator design pattern (I am new to the subject of design patterns), and I was wondering,
Can a decorator interact with more than one component? If A is a decorator of component B, can A have operations that B does not...
Started by Nat10 on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Decorator Pattern
Yes What else would the decoration be? Decorator simply adds.
To add functionality to the object it is decorating.
1.) Yes
2.) Yes, that is the main point of a decorator pattern.
|
|
I think a classic example is that the Window class can have a Border decorator and a ScrollBar decorator in the GoF book.
What are some situations you think, know of, in which the Decorator Pattern solves the problem really well?
Started by Jian Lin on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Example off the top of my head.
I've used the Decorator pattern for managing complex roles.
And so on...
|
|
What is the difference between the Composite Pattern and Decorator Pattern?
Started by coder on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Http://en.wikipedia.org/wiki/Composite_pattern
The decorator pattern allows an entity to completely contain another entity so that ....
The composite pattern allows you to build a hierarchical structure composability .
The decorator pattern.
|
|
I am just starting to learn design patterns and I have two questions related to the Decorator...
I was wondering why the decorator pattern suggests that the decorator implement all public methods of the component of which it decorates?
Can't the decorator...
Started by Ryan on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Class Decorator....
You're thinking of a simple case of extending() { return "foo"; } function bar() { return "bar"; } } // Not what we think of as a Decorator, // really just a subclass.
I think you have have misunderstood Decorator.
|
|
How do I write a decorator that restores the current working directory to what it was before the decorated function was called? In other words, if I use the decorator on a function that does an os.chdir(), the cwd will not be changed after the function...
Started by Daryl Spitzer on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Def preserve_cwd(function): def decorator(*args, **kwargs): cwd = os.getcwd() result = function(*args, **kwargs) os.chdir(cwd) return result return decorator
Here's how it's used:
@preserve_cwd def() /Users/dspitzer
The answer for a ....
|