Can someone give me an example of Decorator pattern in C++ ? I have come across the Java version of it. But C++ i have found it difficult to understand the examples that are given.
+3
A:
Vince Huston Design Patterns, even though its layout is poor, has C++ implementation for most design patterns in the Gang of Four book.
Click for Decorator.
There isn't much difference with Java, except the manual memory handling that you'd better wrap with smart pointers :)
Matthieu M.
2010-06-07 08:43:19
+1 for this website.I always refer to this for cpp implementation.I also think that the messy memory management is the reason you don't see this pattern much in cpp.
David Relihan
2010-06-07 08:53:55
I don't always refer to the implementation, but I appreciate not being spammed by ads and the advices on when to apply, when not to and what it brings in comparison to other related patterns.
Matthieu M.
2010-06-07 09:10:33
+1
A:
I've found the website Sourcemaking to be a pretty good one when it comes to explaining different Design Patterns.
The Decorator design pattern has C++ examples, such as an overview example, a "before and after", and an example with packet encoding/decoding.
Dan
2010-06-07 15:28:30