I have 3 car rental agencies. Each agency requires the data in XML, but in a different format, for example:
Agency 1
<Rental>
<Customer>
<FirstName>test</FirstName>
<LastName>test</LastName>
</Customer>
<Pickup date="07/20/2012"/>
<Dropoff date="07/25/2012"/>
<Deposit cost="100"/>
</Rental>
Agency 2
<Rental>
<Customer>
<FirstName>test</FirstName>
<LastName>test</LastName>
</Customer>
<Pickup>07/20/2012</Pickup>
<Dropoff>07/25/2012</Dropoff>
<Deposit>100</Deposit>
</Rental>
Agency 3
<Rental pickup="07/20/2012" dropoff="07/25/2012" deposit="100">
<Customer>
<FirstName>test</FirstName>
<LastName>test</LastName>
</Customer>
</Rental>
As you can see from above, all 3 basically contain the same information, altough this doesn't have to be the case (some can contain more or less information), but it is structured different, so the way I access it is different. What is the best approach to take so I can write the most minimum code, but be able to adapt to new rental agencies that come along with a different structure?
Right now, I am doing something like this:
public class Agency1
{
SubmitRental()
{
//Parse XML for Agency 1
}
//Other methods for agency 1
}
public class Agency2
{
SubmitRental()
{
//Parse XML for Agency 2
}
//Other methods for agency 2
}
public class Agency3
{
SubmitRental()
{
//Parse XML for Agency 3
}
//Other methods for agency 3
}
In the above, the classes contain the same methods, but the way they are implemented is different. There are some methods, properties, etc that are in some classes, but not in others. Are interfaces the best way to approach this? If so, should everything be made an interface?
In the XML samples above, the data was the same, but the format was different, which led some to bring up mapping the all the different formats to a set of common classes, but what about the scenario where not only is the format different, but the data is different as well?
For example:
Agency 4
<Rental start="07/20/12" end="07/25/12">
<Name>John Doe</Name>
<DriverLicenseNumber>193048204820</DriverLicenseNumber>
<DOB>3/4/64</DOB>
<Rental>