Suggestions for a look up chart/system for setting object properties
So I have written an app to interact between a database and an ecommerce site. The biggest hurdle having been mapping data from one system to the other. This was only a hurdle because on the ecommerce system there is inconsistency with property name and the model used for the objects.
For an example, the model and properties used for Customer and order objects. Dealing with orders or customers requires information from either, but depending on what action you are performing (retrieving orders, sending order updates, uploading customers...etc) there are different objects th开发者_JAVA百科at retain different property names depending on what you are attempting to do despite the fact that you are dealing with ideally the same entity (customers, orders..etc).
To get to my question: Again, following the ecommerce's rules (which I have no control over), I can substitute property values to a default if the source doesn't have values for those properties. What default values these properties get can change also depending on what action is being performed. Therefore, I was looking for some ideas for a system to look up and return values depending on what the object it is and/or what action is being performed.
So an example would be if I was mapping data from my objects to the ecommerce system and say the property value is null, and wanted a single point that I can call into, pass in the source object, destination object, and property and retrieve any values based on rules I define there.
Any suggestions?
Create an adapter class that takes the entity from the econmerce site and translates it to your domain entities. Write all of your application specific logic against the entities you defined without any knowledge of the ecommerce model. If you need to send data back to the ecommerce write a method to translate your entity to the ecommerce entity in your adapter class. This adapter would encapsulate all the logic to populate the default values
精彩评论