Questions tagged [chain-of-responsibility]

Design pattern consisting of a source of command objects and a series of processing objects. One of the Gang of Four's behavioral design patterns.

Design pattern consisting of a source of command objects and a series of processing objects. Each processing object contains logic that defines the types of command objects that it can handle; the rest are passed to the next processing object in the chain. A mechanism also exists for adding new processing objects to the end of this chain.

This is one of the Gang of Four's behavioral , first published in Gamma et al.'s book "Design Patterns: Elements of Reusable Object-Oriented Software".

More information is available on Wikipedia.

160 questions
8
votes
2 answers

Java Generics: chaining together generic function object

I've been struggling with the following problem. I have a series of function objects, each with it's own input and output types defined via generic type arguments in java. I would like to arrange these in a chain so that raw data is input to the…
downer
  • 954
  • 2
  • 13
  • 24
8
votes
4 answers

Design pattern for replacing nested if statements (arrow anti-pattern)

I noticed my code looks really ugly, and is hard to maintain. Basically I need do to some person check. Pseudo code is like this (BTW I can't "cut" anything in query, and it's not really the point of my question): List persons =…
8
votes
3 answers

Would this be a pipeline, a chain of responsibility, or something else?

I'm building a multiprocess architecture that seems to be a strange meld of a pipeline and a chain of responsibility. Essentially, I have a chain of handlers linked up by queues. Each handler will receive an object that represents the input data,…
Jason Baker
  • 192,085
  • 135
  • 376
  • 510
7
votes
6 answers

The Chain of Responsibility Pattern

Could somebody provide a simple explanation of the chain of responsibility pattern? I found the wiki article a bit confusing.
Dollarslice
  • 9,917
  • 22
  • 59
  • 87
7
votes
1 answer

Chain of Responsibility - pass the request through all the chains

I browsed the web but I couldn't find an answer to my question... Lets say I have 3 chains. I want the request to pass all 3 chains (it doesn't matter if the chain can handle the request or not). Is it possible to use CoR pattern for this problem?…
mirta
  • 644
  • 10
  • 25
5
votes
2 answers

How to implement Chain of Responsibility in a testable fashion?

I'd like to implement a Chain of Responsibility pattern, taking care of the 'broken link' problem as follows: public abstract class Handler{ private Handler m_successor; public void setSuccessor(Handler successor) { m_successor =…
FatLlama
  • 123
  • 2
  • 5
5
votes
3 answers

Chain of responsibility using Func

I'm creating a chain of responsibility pipeline using System.Func where each function in the pipeline holds a reference to the next. When building the pipeline, I'm unable to pass the inner function by reference as it throws a…
Ben Foster
  • 34,340
  • 40
  • 176
  • 285
5
votes
1 answer

Implementing Chain of responsibility pattern in python using coroutines

I am exploring different concepts in python and I happened to read upon an example of coroutines which can be used for the chain of responsibility design pattern. I wrote the following code: from functools import wraps def coroutine(function): …
Rivas
  • 85
  • 7
5
votes
3 answers

C# Chain-of-responsibility with delegates

For my understanding purpose i have implemented Chain-Of-Responsibility pattern. //Abstract Base Type public abstract class CustomerServiceDesk { protected CustomerServiceDesk _nextHandler; public abstract void ServeCustomers(Customer…
user274364
  • 1,797
  • 2
  • 20
  • 27
5
votes
2 answers

Executing Chain of Responsibility variation

I have got a pipeline of tasks which basically is a variation of chain of responsibility pattern. A task in my pipeline looks as below internal interface IPTask { bool CanExecute(T instance); T Process(T instance); } ..and my processor…
Mike
  • 3,204
  • 8
  • 47
  • 74
4
votes
2 answers

How do I declare a chain of responsibility using decorators in Ninject?

I'd like to declare a chain of responsibility using decorators in Ninject. Has anyone done that before? Thanks.
4
votes
2 answers

Is the Chain of Responsibility pattern a good replacement for a sequence of conditions?

When you need to execute a sequence of actions in a particular order, is the Chain of Responsibility pattern a good replacement for a sequence of conditions? Is it a good idea to replace a simple method with conditions like this: public class…
Ondrej Sotolar
  • 1,352
  • 1
  • 19
  • 29
4
votes
2 answers

Kotlin chain of responsibility pattern with generics

Using the chain of responsibility pattern I ran into a problem where next chain element was expected to have the same generic type of the first element. I know why this happens: The first handler expects the second handler to use the generic type…
keyboardsamurai
  • 703
  • 1
  • 9
  • 20
4
votes
2 answers

How do I generalize calling a list of functions in C++?

I have the following code which allows me to instantiate and then call a list of void() functions. (I am using https://github.com/philsquared/Catch for unit testing if you wish to compile and run this code). #include "catch.hpp" #include…
spierepf
  • 2,774
  • 2
  • 30
  • 52
4
votes
1 answer

Chain of Responsibility vs Commands in a queue or stack

Why I need to use Chain of responsibility, if I could load all commands into some container and just execute commands one by one. This will make a chain of processing a request in a row. BTW I feel that it is better than CoR because you can remove…
Narek
  • 38,779
  • 79
  • 233
  • 389
1
2
3
10 11