Search code examples
design-patternsarchitecturedecoupling

Decoupling business logic from data source


I have an application that depends on a dll (named datalib) intended to store data in xml format.

There is a tight couple between my app and that dll.

All over the code my app retrieve data using that dll in this manner:

var data = datalib.Parameters.HostAddress;

I want my app to have an ability for replacement of data source (for instance to SQL Server database).

For unfortune, my app within it's business logic convey strongly typed objects from datalib to other modules which depends on datalib tightly to.

What possible ways are available in my situation to achieve the ability for replacement of data source? Am I need to create my own domain layer with the ability to map it's entities to datalib's entities?


Solution

  • Suggest reading up on these concepts from the below links and elsewhere:

    1. Repository Pattern
    2. Data Mapper

    Essentially, you want to achieve loose coupling around the external data access library (datalib.dll). This could be achieved in many ways - from a simple DataAccess class to more extensible Repository type factory classes.

    You would have to make that choice, based on the cost vs. benefits in each approach. Hope this helps.