To make sure I understand what you are asking, here are my assumptions based on my reading of the question:
- The data is some kind of binary format (presumably an image but as you say it could be anything) that can be represented as an array of bytes
- There are a number of processing steps (I'll refer to them as transformations) that can be applied to the data
- Some transformations depend on other such that, for example, you would like to avoid applying a transformation if its pre-requisite has not been applied. You would like it to be robust, so that attempting to apply an illegal transformation will be detected and prevented.
And the question is how to do this in an object-oriented way that avoids future bugs as the complexity of the program increases.
One way is to have the image data object, which encapsulates both the binary data and a record of the transformations that have been applied to it, be responsible for executing the transformation through a Transformation object delegate; and the Transformation objects implement both the processing algorithm and the knowledge of whether it can be applied based on previous transformations.
So you might define the following (excuse my Java-like naming style; it's been a long time since I've done C++):
- An enumerated type called TransformationType
- An abstract class called Transformer, with the following methods:
- A method called 'getType' which returns a TransformationType
- A method called 'canTransform' that accepts a list of TransformationType and returns a boolean. The list indicates transformations that have already been applied to the data, and the boolean indicates whether it is OK to execute this transformation.
- A method called 'transform' that accepts an array of bytes and returns an array of (presumably modified) bytes
- A class called BinaryData, containing a byte array and a list of TransformationType. This class implements the method 'void transform(Transformer t)' to do the following:
- Query the transformer's 'canTransform' method, passing the list of transformation types; either throw an exception or return if canTransform returns false
- Replace he byte array with the results of invoking t.transform(data)
- Add the transfomer's type to the list
I think this accomplishes what you want - the image transformation algorithms are defined polymorphically in classes, but the actual application of the transformations is still 'controlled' by the data object. Hence we do not have to trust external code to do the right thing wrt setting / checking flags, etc.