1

I have a result function which I want to call only when x number of conditions are met, as soon as the last condition is met.

Each condition could be ignorant of every other condition to reduce coupling.

I'm thinking there may be some kind of 'decision' object which you can register your result function with, and you can specify your x number of conditions. When each condition is met it calls into the decision object to let it know it has been met. When the last condition is met, the result function is called.

I've come across thread-blocking objects which do this, but I'm not looking for a thread-blocking answer.

Is there a general term for what I'm describing?

Tim Gradwell
  • 2,312
  • 5
  • 24
  • 25

2 Answers2

4

Beyond being a pattern, this is dataflow programming:

In computer programming, dataflow programming is a programming paradigm that models a program as a directed graph of the data flowing between operations, thus implementing dataflow principles and architecture.

Pipes and Filters is an enterprise pattern that can be used for dataflow programming.

For Java, you can see this question: Dataflow Programming API for Java?

Community
  • 1
  • 1
mmdemirbas
  • 9,060
  • 5
  • 45
  • 53
1

I'm not sure if there's a general term for this, but it seems like a combination of the mediator pattern and the observer pattern -- if I had to give it a name, I might call it "guarded function" or "guarded method".

casablanca
  • 69,683
  • 7
  • 133
  • 150
  • the word "guard" did come to mind, and someone else mentioned mediator to me - although it seems to be an inverse of the observer - observer is many observers to one event - I need one observer to many events :-) – Tim Gradwell Jul 19 '12 at 15:34
  • @TimGradwell: Observer by itself doesn't imply one or many observers. Maybe its synonym, publish-subscribe, makes more sense -- you have multiple publishers and one subscriber. – casablanca Jul 19 '12 at 16:12