I'm looking for an appropriate design pattern to accomplish the following:
I want to extract some information from some "ComplexDataObject" (e.g. an Image) and save the relevant information in a more suitable format, let's call it a NiceDataObject.
Partial information is extracted from the ComplexDataObject in several steps. The output from one step may be required as input in a later step. Since output and input may be of different types, I don't know if I can use some of the existing patterns like "pipes and filters", "chain of responsibility" or the like?
The following piece of "code" hopefully makes it clear what I want to achieve
NiceDataObject ProcessingMethod1(ComplexDataObject cdo) {
InfoType1 infoPiece1 = extractInfoMethod1(cdo)
InfoType2 infoPiece2 = extractInfoMethod2(cdo, infoPiece1)
InfoType3 infoPiece3 = extractInfoMethod3(cdo, infoPiece2)
InfoType4 infoPiece4 = extractInfoMethod4(cdo, infoPiece2, infoPiece3)
NiceDataObject structuredInfo = PutItTogether(cdo, infoPiece1, infoPiece2,
infoPiece3, infoPiece4)
return structuredInfo
}
To make matters more complicated, I'd ideally also be able to have the possibility of handling another complex data type (say AnotherComplexDataObject) in the same manner to produce the desired NiceDataObject.
NiceDataObject ProcessingMethod2(AnotherComplexDataObject cdo) {
InfoType1 infoPiece1 = extractInfoMethod1(cdo)
InfoType5 infoPiece5 = extractInfoMethod5(cdo, infoPiece1)
InfoType6 infoPiece6 = extractInfoMethod6(cdo, infoPiece5)
NiceDataObject structuredInfo = PutItTogether2(cdo, infoPiece1, infoPiece6)
return structuredInfo
}
This would allow me to write a general API function something like
NiceDataObject Process(SomeComplexDataObject cdo)
where SomeComplexDataObject is a baseclass for ComplexDataObject and AnotherComplexDataObject.
If possible, I'd like to "register" processing step methods (i.e. extractInfoMethod1, ..., extractInfoMethod6 above) for flexibility and since I want to be able to peek at the intermediary data.
If it matters, I'm using Python, and use a C-like "code" above only to illustrate that input and output typically are of different types.