Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design Patterns Chain of Resposibility Vs Decorator

How Chain of Responsibility Pattern Differs from Decorator Pattern..?

like image 433
Mind Dead Avatar asked Sep 15 '10 19:09

Mind Dead


People also ask

Why would I ever use a Chain of Responsibility over a decorator?

Decorator is used when you want to add functionality to an object. COR is used when one of many actors might take action on an object. A particular Decorator is called to take an action, based on the type; while COR passes the object along a defined chain until one of the actors decides the action is complete.

What is the difference between Decorator and Strategy pattern?

The strategy pattern allows you to change the implementation of something used at runtime. The decorator pattern allows you augment (or add to) existing functionality with additional functionality at run time.

What type of design pattern is decorator?

Decorator design pattern is one of the structural design pattern (such as Adapter Pattern, Bridge Pattern, Composite Pattern) and uses abstract classes or interface with composition to implement.

What is chained responsibility pattern?

Chain of responsibility pattern is used to achieve loose coupling in software design where a request from the client is passed to a chain of objects to process them.


1 Answers

I generally think of the Decorator as "adding" to some thing, where as Chain of Responsiblity is more like handling something thing.

In comparing the two patterns (besides being apples and oranges) the biggest difference is the Chain of Responsibility can kill the chain at any point.

Think of decorators as a layered unit in which each layer always does pre/post processing. Chain of Responsibility is more like a linked list, and generally 1 thing handles processing.

The Chain of Responsibility pattern allows for multiple things to handle an event but it also gives them the opportunity to terminate the chain at any point.

like image 124
Nix Avatar answered Sep 20 '22 06:09

Nix