Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

The Deal with Decorators


Go to End


4 Posts   1775 Views

Avatar
UncleCheese

Forum Moderator, 4102 Posts

28 November 2008 at 5:28am

Can someone please explain to me once and for all what the purpose of a DataObjectDecorator is? What is the advantage of creating GalleryFile as a decorator of File over just creating a subclass of File? What is the advantage of creating ForumMember as a decorator over just subclassing Member?

Avatar
jam13

121 Posts

28 November 2008 at 5:41am

AFAIK, the difference is that it affects all the existing uses of the class, so code which uses the File class is in effect using GalleryFile class. This allows you to extend core classes without changing the core files themselves.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

28 November 2008 at 5:48am

Yeah, that makes sense. But if a GalleryFile can only belong to a GalleryPage, and if a ForumMember can only belong to a Forum, then why not just use subclasses? A gallery page has many GalleryFiles, and a Forum has many ForumMembers. I mean, why would all your other instances of File need access to those new fields, anyway?

Oh well.. thanks for the explanation. I think I get it now. I just need to find a use for it.

Avatar
jam13

121 Posts

28 November 2008 at 6:03am

A use that I can think of off the top of my head is that modules can add functionality to existing classes without modifying their code. For example the ecommerce module can add extra address fields to the Member class.