简体   繁体   English

技术架构:服务层还是没有?

[英]Technical architecture : Service layer or not?

we have a platform composed of few applications. 我们有一个由少量应用程序组成的平台。

We have to develop an API which must factorize all interaction to a database. 我们必须开发一个API,该API必须将与数据库的所有交互都分解为因素。 In this API, we will too have a version of the database in XML format. 在此API中,我们还将拥有XML格式的数据库版本。 The XML format will be used just by one application. XML格式将仅由一个应用程序使用。

Our application are developped in a classic architectural : dao - service layer - presentation layer. 我们的应用程序是在经典的体系结构中开发的:dao-服务层-表示层。

The DAO layer will be moved into API. DAO层将移入API。 No problem on that point. 在这一点上没有问题。 In many application, the service layer is just a gateway between presentation & dao layer without specific business code. 在许多应用程序中,服务层只是表示层和导引层之间的网关,而没有特定的业务代码。

So my questions are : 所以我的问题是:

  • should we create the API with a Service layer for each dao ? 我们是否应该为每个dao创建一个带有Service层的API?
  • if yes, so keep a service layer in application which call service layer from API ? 如果是,那么在应用程序中保留一个服务层,该服务层从API调用服务层?
  • should we create a service layer in API which manage the factory (database/XML), but that mean each application has to give an information to choose the dao to select (when just one application has this need) ? 我们是否应该在API中创建一个用于管理工厂(数据库/ XML)的服务层,但这意味着每个应用程序都必须提供信息以选择要选择的dao(当只有一个应用程序有此需要时)?
  • or just create all dao in different packages for database & xml in API, keep factory in the application which has the need, and call dao (database) in all others ? 还是仅在API中的数据库和xml的不同包中创建所有dao,将工厂保留在有需要的应用程序中,然后在所有其他应用中调用dao(数据库)?

Need help ! 需要帮忙 ! :p I'm lost... :p我迷路了...

FYI, we are in Java 1.6 with Spring 3.1.1. 仅供参考,我们在Java 1.6和Spring 3.1.1中。 JDBC Template in DAO for moment. DAO中的JDBC模板暂时。 We are looking informations about spring data jdbc to replace JDBC Template. 我们正在寻找有关Spring数据jdbc的信息,以替换JDBC模板。 Any suggestion about that can be appreciated ^^ [ No Hibernate - JPA solution ] 对此的任何建议都值得赞赏^^ [No Hibernate-JPA solution]

Thank you. 谢谢。


[edit 1] [编辑1]

In other word, keep a service layer in application & in the API is a way for me to have an abstraction layer. 换句话说,在应用程序和API中保留服务层是我拥有抽象层的一种方式。 If we have to modify the database structure, maybe we don't have to edit all applications if we can make some changes directly in the service layer of API too. 如果我们必须修改数据库结构,那么如果我们也可以直接在API的服务层中进行一些更改,那么也许不必编辑所有应用程序。

Imagine 3 possibilities : 想象3种可能性:

  1. service layer in API with factory to choose which dao to use (xml/database) 具有工厂的API中的服务层,以选择要使用的dao(xml /数据库)
  2. just dao in API 只是在API中
  3. service layer in API for database & specific layer in API for XML 数据库API的服务层和XML API的特定层

What solution do you choose ? 您选择什么解决方案?

[edit 2] [编辑2]

Is it interesting to create an unique class to call the API ? 创建一个唯一的类来调用API有趣吗? like in a Facade design Pattern. 就像在立面设计模式中一样。

Use the Service Layer for what is meant to do: provide real world services, by using one ore more DAOs per service offered (and other stuff like managing transactions, sanitizing String s and other things like that). 使用服务层实现目的:通过提供的每项服务使用一个或多个DAO来提供真实的服务(以及其他诸如管理事务,清理String等之类的东西)。

If you (together with a more experienced coworker) think you don't need this service layer, then do not put it into your architecture. 如果您(与经验丰富的同事一起)认为您不需要此服务层,则不要将其放入体系结构中。 But make sure to create a proof of concept of your architecture (this may contain the implementation of a somewhat complex functionality of the system or part of it) so you can evaluate it later to demonstrate if you really don't need such layer (or if you do). 但是请确保创建您的体系结构的概念证明(其中可能包含系统或部分系统的某种复杂功能的实现),以便稍后进行评估以证明您是否真的不需要这种层(或如果您这样做)。

My understanding is that you need to decouple and reuse the business layer from the presentation layer, having multiple client applications using the same business implementation. 我的理解是,您需要使业务层与表示层脱钩并重用,使多个客户端应用程序使用同一业务实现。

In this case you need to implement the service layer in the API. 在这种情况下,您需要在API中实现服务层。 Some advantages: 一些优点:

  1. You don't need to repeat the service implementation for any client application handling the presentation. 您无需为任何处理演示的客户端应用程序重复执行服务。
  2. You can easily decouple the database model design from the business. 您可以轻松地将数据库模型设计与业务脱钩。 Design patterns (DTO, Facade) and cross cutting concerns may be easily introduced. 设计模式(DTO,Facade)和横切关注点可以很容易地引入。
  3. A well designed service layer will require a minimum amount of modifications, compared to DAOs holding DB implementation details. 与拥有数据库实现细节的DAO相比,设计良好的服务层将需要最少的修改。

In this API, we will too have a version of the database in XML format. 在此API中,我们还将拥有XML格式的数据库版本。 The XML format will be used just by one application. XML格式将仅由一个应用程序使用。

By providing this implementation via the API more client applications will be able to use it in the future, if needed. 通过API提供此实现,如果需要,将来更多的客户端应用程序将能够使用它。

Spring remoting is offering excellent tools for such a design (RMI, HTTP invoker etc) Spring远程处理为此类设计提供了出色的工具(RMI,HTTP调用程序等)

I don't see any added value in proving an API for DAOs. 在证明DAO的API方面,我没有看到任何附加价值。

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

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