17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1193 Views |
-
The Deal with Decorators

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?
-
Re: The Deal with Decorators

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.
-
Re: The Deal with Decorators

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.
-
Re: The Deal with Decorators

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.
| 1193 Views | ||
|
Page:
1
|
Go to Top |

