• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Is there a difference in how you implement Chain of Responsibility and Decorator pattern?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's fair to say that they are quite similar to each other.
The only difference that I know is the intent.

Chain of Responsibility: Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. Not all objects may get chance or be able to handle the request.
Decorator : Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. All decorator objects handle the request by enhancing the data in their own way.

But is there a difference if implementation? Apart from the fact that in Chain of responsibility you could break the chain at any point?

The following is an example of Decorator Pattern. But if you had asked me to write an example of Chain of responsibility, I could have written the same example.
Yes I could have also added the condition where I check if the request is to be forwarded further and then break the chance if not. But is that a mandatory thing for it to qualify as a Chain of Responsibility Pattern? If it's not then is the following not an example of both Chain of Responsibility and Decorator pattern?

 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic