Nick Hodges My pleasure, Nick. What Gerrit shows for the Decorator is not so different to Yanniel's examples. There are also some articles out there which suggest combining the Decorator with the Fluent Interface. But I haven't decided yet how I feel about FI.
Nick Hodges Probably helpers are not really decorators, at least not as the examples we have seen. However, they do meet the requirements of the definition. The difference, as I see it, is that the examples show a decorator aggregating within itself the original class. I should add a disclaimer about wording, since I struggled with the description I presented, I think it conveys the sense, though it may not be entirely accurate.
Sorry, but i still quite not getting what decorator is,i've read the wiki about it, so is it the same as create a descendant class or is it more like helper class?
Iwan Cahyadi Sugeng Decorator is just like a descendant class, the trick is that it takes an instance of base class in constructor, which allows you to decorate existing instances without needing to change the declaration of existing objects of base type
Nick Hodges Yes, his examples are pervasive. That one is a match to the one in my first link, which he published on Codeplex. Of the examples I have seen, his are the clearest to understand.
Why yes, Nick. Indeed I do!
ReplyDeletehttp://www.jazziesoftware.us/decoratorpatterninvclinwild.png
Alternately, you can download the ModelMaker Design Patterns manual here: http://www.modelmakertools.com/modelmaker/download.html
ReplyDeleteDecorator pattern in the VCL?
ReplyDeleteStart with TCompressionStream :)
A
Bill -- Hey, thanks for the pointer to that MM document. Very nice.
ReplyDeleteNick Hodges My pleasure, Nick. What Gerrit shows for the Decorator is not so different to Yanniel's examples. There are also some articles out there which suggest combining the Decorator with the Fluent Interface. But I haven't decided yet how I feel about FI.
ReplyDeleteI use this a lot to add functionality to TStream. An example would be the TGpBufferedStream class from http://code.google.com/p/gpdelphiunits/source/browse/trunk/src/GpStreams.pas.
ReplyDeleteOn the other hand, aren't all 'helpers' decorators?
Primož Gabrijelčič Helpers were my first thought, but I thought they might take us down the FreeAndNil path.... ;)
ReplyDeleteI don't know if helpers are considered to be the decorator pattern or not, actually.
ReplyDeletePrimož Gabrijelčič Thanks for the link -- I'll give it a look.
I've seen the word "decorator" mentioned in DUnit sources.
ReplyDeleteNick Hodges Probably helpers are not really decorators, at least not as the examples we have seen. However, they do meet the requirements of the definition. The difference, as I see it, is that the examples show a decorator aggregating within itself the original class. I should add a disclaimer about wording, since I struggled with the description I presented, I think it conveys the sense, though it may not be entirely accurate.
ReplyDeleteOndrej Kelle Good thought. DUnit may be one of the better sources to explore for patterns.
ReplyDeleteMaybe but it has so much decoration it is difficult to find the 'meat'.
ReplyDeleteSorry, but i still quite not getting what decorator is,i've read the wiki about it, so is it the same as create a descendant class or is it more like helper class?
ReplyDeleteIwan Cahyadi Sugeng Decorator is just like a descendant class, the trick is that it takes an instance of base class in constructor, which allows you to decorate existing instances without needing to change the declaration of existing objects of base type
ReplyDeleteThere a simple but excellent illustration of the pattern here:
ReplyDeletehttp://www.yanniel.info/2011/08/decorator-pattern-delphi-single.html
Nick Hodges Yes, his examples are pervasive. That one is a match to the one in my first link, which he published on Codeplex. Of the examples I have seen, his are the clearest to understand.
ReplyDelete