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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

DataObjectDecorator vs. Extending a Class


Go to End


3 Posts   1698 Views

Avatar
ttyl

Community Member, 114 Posts

6 May 2010 at 4:16am

Why is it preferable to use DataObjectDecorator rather than extending a class? I want to add a 'many_many' to my Member class and it craps out when using DataObjectDecorator, but works fine when I extend the class. What is the difference? Why would I use one or the other?

thanks.

Avatar
Willr

Forum Moderator, 5523 Posts

6 May 2010 at 10:48pm

You would still point to 'Member' in your Many_Many not the extension specifically. A decorator is useful as you can apply multiple decorators per object and you won't have to rewrite core functionality / queries to use your custom class. DataObjectDecorators 'append' functionality to an existing object which can be a cleaner way to extend the functionality.

Avatar
ttyl

Community Member, 114 Posts

7 May 2010 at 6:56am

it actually made more sense in my project to go a different direction on this particular problem, but that is good to know. thanks.