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.

General Questions /

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

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

DataObjectDecorator vs. Extending a Class


Reply


3 Posts   1251 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, 5513 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.