I am working on a business layer functionality.
There are two layers :-
1) Entity Data Model Layer which is the logical layer
This logical layer maps to a storage layer.
There are different classes in each of this layer.
The data storage layer has subject, test and result as objects
The logical layer has entity as objects.
I am writing a code which accepts an object of logical layer and converts it to storage layer objects.
It does so by reading the schema of the logical layer.
The schema of the logical layer is stored in an xml file and it has attributes which map to physical layer.
My code will interpret this schema and convert to appropriate physical layer objects.
The class which I have written is as follows :-
DataModelToStorageTranslator
{
IStorageLayerObject TranslateToStorageLayer(ObjectOfLogicalLayer);
}
The different classes of the storage layer are derived from the IStorageLayerObject.
The client will check the type of object at runtime.
Is there a better way to achieve the same ?
My implementation is in C#
Thanks,
Vivek
Unless there is a very good reason for using XML, I would avoid it. If you have a fixed number of objects that will need conversion from logical layer to storage layer I would suggest to create a
DataModelToStorageTranslatorfacade like this:That would give you more type safety as you will not need to check object types and cast. You will need to extend your interface anytime you want to add new objects (which I think is a good way of doing it for smaller projects).