views:

181

answers:

1

I'm working on a project where I need to add some functionality to a service object and using a decorator to add it in seems like a good fit. However, I've only ever used decorators with simple beans, never on a singleton like a service object. Has anyone ever done this before and what are the pros and cons? In this case I don't think creating a subclass will work so a decorator seems to be a good fit. What are your thoughts on doing this?

A: 

I frequently use the decorator pattern on my singleton Service objects. In fact, every service extends a BaseService object with methods like $throw which allow me to log my business layer errors to an RSS feed.

Go for it.

Aaron Greenlee