Acquisition accumulator (software design)

176 Views Asked by At

I need some help on software design. Let's say I have a camera that gets acquisitions, send them to a filter, and display the images one at a time.

Now, what I want is to wait for two images and after that send the two images to the filter and both of them to the screen.

I thought of two options and I'm wondering which one to choose: In my Acquisitioner (or whatever) class, should I put a queue which waits for two images before sending them to the Filterer class? Should I put an Accumulator class between the Acquisitionner & Filterer?

Both would work in the end, but which one do you think would be better?

Thanks!

2

There are 2 best solutions below

0
On

It depends. But, if all that your queue does is waiting for a second image to come, i reckon you could simply implement it right in the Acquisitioner.

On the other hand, if you want to incorporate whatever additional functionality there, then added modularity and all the benefits that come hand in hand with it would not hurt one tiny bit.

I don't think it matters all that much in this particular case.

0
On

To give a direct answer, I would implement the Accumulator policy in a separate object. Here's the why:

Working on similar designs in the past, I found it very helpful to think of different 'actors' in this model as sources and sinks. A source object would be capable of producing or outputting an image to the attached sink object. Filters or accumulators in this system would be designed as pipes -- in other words they would implement interfaces of both a sink and a source. Once you come up with a mechanism for connecting generic sources, pipes, and sinks, it's very easy to implement an accumulation policy as a pipe, which for every nth image received, would hold on to it if n is odd, and output both of them, if n is even.

Once you have this system, it will be trivial for you to change out sources (image file readers, movie decoders, camera capture interfaces), sinks (image file or movie encoders, display viewers, etc), and pipes (filters, accumulators, encoders, multiplexers) without disrupting the rest of your code.