Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > design q: decorator pattern

Thread Tools

design q: decorator pattern

James Kanze
Posts: n/a
On Jul 10, 2:51 pm, "Daniel T." <(E-Mail Removed)> wrote:
> On Jul 10, 6:07 am, Chris Forone <(E-Mail Removed)> wrote:

> > is there a possibility to implement the decorator-pattern
> > without new/delete (nor smartpt)?

> Yes, as Michael Doubez has shown, but then the Decorator is
> sharing its component with something else, which isn't
> optimum.

That wasn't the case in Michael's example. There was a higher
level component which set up the pattern, but that's always the

> > if not, how to ensure correct deletion of the objects?

> By simply using a smart pointer, or putting deletes in the
> appropriate places. Why would you want to avoid using
> new/delete or smart pointers?

Because it's not generally necessary? Because in some cases,
someone else is already managing the object lifetime? (One of
the frequent uses of the decorator pattern in my code is a
filtering streambuf. And if the decorated streambuf comes from
std::cin, I'd better not delete it.)

> The point of the Decorator pattern is that the Decorator has
> sole use of the concrete Component it contains so it can
> control what the component receives from the world at large.

Sole use for a certain period of time, maybe (although even this
isn't really guaranteed---or even usual).

> To ensure this, the Decorator must have ownership of the
> component it contains.

I don't know where you get this from. There are cases where the
decorator must be the only object accessing the decorated, for
the period of time the decorator exists, but there probably the

James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 1 01-22-2012 10:48 PM
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 0 01-22-2012 10:26 PM
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 0 01-22-2012 10:25 PM
May I have a example of design pattern of "composite", I still feel fuzzy after reading book of Addison-Wesley's"design pattern " C++ 1 08-31-2007 04:09 AM
explanations about the Decorator design pattern Jean Lutrin Java 8 11-18-2004 05:40 PM