Architecture – Modular Architecture for Processing Pipeline

Architecturedesign-patterns

I am trying to design the architecture of a system that I will be implementing in C++, and I was wondering if people could think of a good approach, or critique the approach that I have designed so far.

First of all, the general problem is an image processing pipeline. It contains several stages, and the goal is to design a highly modular solution, so that any of the stages can be easily swapped out and replaced with a piece of custom code (so that the user can have a speed increase if s/he knows that a certain stage is constrained in a certain way in his or her problem).

The current thinking is something like this:

struct output; /*Contains the output values from the pipeline.*/

class input_routines{
    public:
    virtual foo stage1(...){...}
    virtual bar stage2(...){...}
    virtual qux stage3(...){...}
    ...
}

output pipeline(input_routines stages);

This would allow people to subclass input_routines and override whichever stage they wanted. That said, I've worked in systems like this before, and I find the subclassing and the default stuff tends to get messy, and can be difficult to use, so I'm not giddy about writing one myself. I was also thinking about a more STLish approach, where the different stages (there are 6 or 7) would be defaulted template parameters.

Can anyone offer a critique of the pattern above, thoughts on the template approach, or any other architecture that comes to mind?

Best Answer

The design is highly dependant on what the different stages actually do. I mostly prefer pure virtual functions over non-pure virtual functions (abstract classes).

Common stages can be grouped together in abstract subclasses. By deriving from the main abstract class you still can still adjust every stage, but by deriving from a subclass you can reuse existing behavior which is already written. It tends to be less messy, as you mention for virtual methods.

If the different stages can also exist on their own (outside of the entire pipeline), also consider writing classes to seperate this behavior.

Related Topic