0
Good example of decorator pattern
Hi Every one mostly talks about decorator pattern with pizza example. I got idea about usage of this pattern as it helps avoid class explosion. However, Could someone please suggest a good example apart from pizza for decorator pattern?
6 odpowiedzi
+ 1
Ketan Lalcheta ,
Please add a python tag.
Two good examples of real-world uses of Python decorators I saw on YouTube were timing how long a function takes to execute and writing a log entry every time a function executes.
+ 1
Ketan Lalcheta ,
OK. I see.
"The DecoratorPattern is a pattern described in the [1994] DesignPatternsBook. ... This is not to be confused with PythonDecorators ..." --
https://wiki.python.org/moin/DecoratorPattern
How unfortunate that the names are so similar.
+ 1
Yeah. Thats why I had not tagged any language as this is generic to all. Also , i had no sample code for this question to make it specific to any language.
0
Ketan Lalcheta ,
What is not the same thing?
0
You are talking about decorator from python. This is the concept which is applied to functions. AFAIK, method / function decorator is limited to Python only. Is this correct?
Now, coming to my query. My concern is not related to function decorators. This is a generic concept applicable to all object oriented programming language.