Decorator Pattern Pros and Cons

Pros: 

  • Decorators provide a flexible alternative to subclassing for extending functionality
  • Decorators allow behavior modification at runtime rather than going back into existing code and making changes
  • Decorators are a nice solution to permutation issues because you can wrap a component with any number of decorators
  • The decorator pattern supports the principle that classes should be open for extension but closed for modification

Cons:

  • Decorators can result in many small objects in our design, and overuse can be complex
  • Decorators can cause issues if the client relies heavily on the components concrete type
  • Decorators can complicate the process of instantiating the component because you not only have to instantiate the component but wrap it in a number of decorators
  • It can be complicated to have decorators keep track of other decorators because to look back into multiple layers of the decorator chain starts to push the decorator pattern beyond its true intent
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: