Question

My project current goal is to create a one stop shop for all the data retrieval either its coming from the service or DB. So we created a WCF solution using Repository pattern that exposes methods to the calling clients and internally it calls either third party services or DB to get the data.

When we get the data from the third party API, data is returned in a proxy class and we happen to handle to deal with a BIG object that has many nested classes and lot of properties. In this scenario as explained above, What is the best thing to do:

  1. Since those proxy classes are big for my situation, Use proxy classes all over the project and return proxy object.
  2. Create local business object, Parse the third party business object to local object and return my local object:

    public class ThirdPartyRepository
        {
            public MyData GetData()
            {
                //Call third party service method
                ThirdPartyProxyClass proxyClass = ThirdPartyServiceReference.GetData();
    
                //Parse object to my object
                MyData data = new MyData() {
                  //Parse properties
                  ID = proxyClass.ID
                };
    
                return data;
            }
        }
    
Was it helpful?

Solution

You are implementing the Adapter pattern. In this case, it's much better to have your own business object to decouple your consumers from the backend repo. In this way, if some external service change the API, there is only one place where the code must be changed. Also you have full control of what and how the data is returned.

http://en.wikipedia.org/wiki/Adapter_pattern

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top