简体   繁体   English

从第三方 Web 服务和应用程序的专用数据库检索客户字段时的 CustomerDAO 替代方案

[英]CustomerDAO alternative when Customer's fields are retrieved both from a third-party web-service and application's dedicated database

I have a Customer class.我有一个Customer类。 Its private field is a CustomerDAO interface which database-access methods are called by myCustomer.getAge() for example.它的私有字段是一个CustomerDAO接口,例如由myCustomer.getAge()调用数据库访问方法。 CustomerDAO retrieves data from the application's dedicated database. CustomerDAO 从应用程序的专用数据库中检索数据。

The problem is that a few fields of Customer now have to be retrieved from a third-party web-service.问题是现在必须从第三方 Web 服务中检索Customer的一些字段。 Logically calling some web-service doesn't belong to CustomerDAO (which is intended for communicating with a single database, right?).从逻辑上讲,调用某些 Web 服务不属于CustomerDAO (旨在与单个数据库进行通信,对吗?)。

What is the industry recommended approach in such cases?在这种情况下,行业推荐的方法是什么?

Shall I just add another field CustomerWebServiceDAO (as interface) to Customer ?我是否应该向Customer添加另一个字段CustomerWebServiceDAO (作为接口)? And my Customer would use internally two different instances ( CustomerDAO and CustomerWebServiceDAO ).我的Customer将在内部使用两个不同的实例( CustomerDAOCustomerWebServiceDAO )。 So DAO gets split into 2 separate classes... What if next I need access to another Web-service plus an additional database?所以 DAO 被分成 2 个独立的类……如果接下来我需要访问另一个 Web 服务和一个额外的数据库怎么办? What better solution/pattern can be used?可以使用什么更好的解决方案/模式?

Adding web-service methods to initial CustomerDAO interface would mix database access with web-service access, which I think is not good.将 web 服务方法添加到初始 CustomerDAO 接口会将数据库访问与 web 服务访问混合在一起,我认为这并不好。

If I understand your question right you need to have a database service which has all GRUD operation of Customer and assume it will be called CustomerDBDao and another service Called CustomerAPIDao which is responsible of all web service operations and all services is called in a general service called CustomerDAO which is filling data from both services and generate One Unified POJO this concept is called adapter design patter如果我理解您的问题是正确的,您需要有一个数据库服务,其中包含Customer 的所有 GRUD 操作并假设它将被称为CustomerDBDao和另一个名为CustomerAPIDao 的服务,它负责所有 Web 服务操作,所有服务都在一个名为的通用服务中调用CustomerDAO正在填充来自两个服务的数据并生成一个统一的 POJO,这个概念被称为适配器设计模式

https://www.tutorialspoint.com/design_pattern/adapter_pattern.htm https://www.tutorialspoint.com/design_pattern/adapter_pattern.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 保留没有ID的第三方类 - Persisting third-party classes with no ID's 当第三方客户致电我的网络服务时致电控制器 - Call Controller when third party client call my web-service 调用Web服务对象的方法 - Call web-service's object's method 在Web应用程序中由第三方代码创建的线程中记录未捕获的异常 - Logging uncaught exceptions in threads created by third-party code in web application 来自 java 桌面应用程序的 Web 服务 - Web-service from a java Desktop-application 从Swing应用程序中托管Web服务 - Host a web-service from within a Swing application 如何将权限和代码库属性放入第三方jar的清单? - How to put Permissions and Codebase attributes into third-party jar's manifest? Maven-我可以在应用运行时添加第三方依赖项吗? - Maven - can i include third-party dependencies during app's runtime? 使用 IAM 用户的访问密钥为第三方 AWS 账户代入角色失败 - Failed to assume role for third-party AWS account using IAM user's access key 尝试在 Postgresql 数据库中存储来自 Web 服务的图像 - Trying to Store Image from web-service in Postgresql Database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM