I am trying to develop an API that tries to integrate features of various service providers. I am at the phase of developing a model(class structure that identifies with the context of domain) that helps in unifying the fields for data that gets sent out to different service providers.
The problem I am trying to solve is to choose whether I consolidate fields from different service providers to create a model which is completely generic or have a model with common fields alongside provider specific fields.
Eg: I have a car rental API which tries to interface with multiple vendors. Each vendor has an API which lets me search of cars in an area with-in a car category. But each vendor-api has it's own added unique capabilities which separate them from their competition.
When I start out integrating with different vendors, I would like my API to do just the basic feature search - for which I can identify fields required for the common model. But as my API evolves I want to expose vendor-unique search parameters through my API. When I am in the process of expanding the features, do I separate fields related to them into different classes or compose them in existing model or do i add those fields to the common model and interpret unique fields based on the context available from the data.
Approach 1 :
CarReservation{
String userName;
String id;
// in millis
long startDate;
long endDate;
CarCategory carCategory;
//--end common model
// only vendor 1 supports discounts on referrals
Referral referral;
// only vendor 2 supports delivering and pick up from home
Address homeDeliveryAddress;
...
}
Approach 2 :
CarReservation{
String userName;
String id;
// in millis
long startDate;
long endDate;
CarCategory carCategory;
//--end common model
vendor_1_name : {
// only vendor 1 supports discounts on referrals
Referral referral;
}
vendor_2_name : {
// only vendor 2 supports delivering and pick up from home
Address homeDeliveryAddress;
}
..
}
The advantage of using single common model(Approach 1) is it's cleaner, but over time as more vendors get added with very specific functionality - the model gets bloated with too many ungrouped fields. I understand we can organize the model better with a hierarchy even with many fields.
The advantage of using separate composite model classes(Approach 2) for different vendors is that it would help us group fields better and allow for isolating changes required in interpreting the data. But downside is that it exposes vendor specific fields.
Please let me know if the direction in which I'm heading is the right one or if there is another/several other approaches that I should be considering which would help with adding more features into the API. Let me know if you need further details/information related to the question.
PS: The sample model(CarReservation) I mentioned in the example is something I haven't thought about too much. I am actually modeling in a different domain, details of which I cannot disclose. :)