I am a class to transform xml data based on specifications. There are multiple different input formats and corresponding sets of specifications. These specifications can often be grouped and have a natural hierarchical structure.
I want to make it so you can add custom functionality easily, and make it so the base transformation class simply applies that functionality. Luckily, I can use the same parameters for all of the functionality.
I have come up with the design below, but I feel like there is probably some way to improve it, or just a completely different design to use. I would appreciate any feedback, thanks!
abstract class baseTransformer
{
int x = 10;
XmlDocument inputDocument;
XmlDocument outputDocument;
public delegate void CustomFunction(baseTransformer obj);
protected Dictionary<string, CustomFunction> delegates;
protected void transform()
{
//read in what delegates to use from JSON
//apply delegates
}
protected abstract void doTransform();
}
class derivedTransformer : baseTransformer
{
protected int y = 20; //instance variables might be needed
public derivedTransformer()
{
delegates.Add("myFunc", new CustomFunction(MyFuntionality));
}
protected void MyFuntionality(baseTransformer obj)
{
derivedTransformer myObj = (derivedTransformer)obj;
//do stuff
}
protected override void doTransform()
{
//do some other stuff and then call transform
transform();
}
}
Aucun commentaire:
Enregistrer un commentaire