简体   繁体   中英

properly implementing interface to expose web service

I have a 3-layered ASP.NET MVC application. The BLL references another project where I have web service proxy classes for payment gateway. Right now I'm using development web service but later will switch to production one.

I am trying to expose the web service to BLL via a class implementing interface (so I can easily swap from dev to production service) however I'm not sure how to use the interface properly in this scenario. I figured there are two options.

  • create a new class and implement the interface. Inside the implemented methods call the identically named web service methods (in proxy class). Expose this class to BLL.
  • create a new class, inherit the web service proxy class and also implement the interface. This effectively leaves the newly created class blank. Expose this class to BLL.

Please advise on which method is better.

I would suggest the adapter design pattern . You would use a class wrapping the service functionality (adaptor class). Then you would use the adaptor class for the rest of the project, as if it was the actual service. When you are ready to switch to the new service, the change would be made only on the adaptor class.

Hope I helped!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM