Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » The Deal with Decorators

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

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

Page: 1
Go to End
Author Topic: 1298 Views
  • UncleCheese
    Avatar
    4085 Posts

    The Deal with Decorators Link to this post

    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?

  • jam13
    Avatar
    121 Posts

    Re: The Deal with Decorators Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: The Deal with Decorators Link to this post

    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.

  • jam13
    Avatar
    121 Posts

    Re: The Deal with Decorators Link to this post

    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.

    1298 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.