I have existing Calss MyParser which has methods to parse XML and get certain values, Currently It uses XPath to do this.
class MyParser
{
public Parse(xmldoc) { ... }
public GetProperties(...) { ... }
public Validate(...) { .... }
}
usage:
MyParser myParser = new MyParser();
myParser.Parse();
....
MyParser.GetProperties(...);
....
MyPaser.Validate(...);
At that time the class was designed there was no schema was defined for the XML. This code is already in product.
Now in the later version of the product schema has been defined for this XML and also XML structure also changed. So in the current version of the product I decided to use Schema class (class generated out of XSD) to parse this XML,
So the product should support both the logic which means it should support parsing both the XML types. I don't want to change the code from where the class is instantiated and used. To identify which XML has been passed to Myparser, there is a tag introduced in newer schema.
I can change the already existing parse method by adding condition like below
I don't want to do this structured programming way. Is there any well defined design pattern to address this problem in OOPS way?
// code get version info from XML
if(version exists and version == 2)
{
// existing code
}
else
{
// new code.
}
Aucun commentaire:
Enregistrer un commentaire