简体   繁体   English

Java应用程序的分层体系结构设计

[英]DESIGN of layered architecture for a java application

I have a code with following architecture 我有以下架构的代码

1)Business objects  (Represents business object (BO) )
2)DataBasedModel classes (Maps to DB tables)

Layered Architecture 分层架构

1)DAO (reads /write BO to DB, convers BO to DBModels and vice versa)
2)Each table has a DAO
3)I plan to have a manager layer on top of DAO.Manager will call DAOS.Manager handels business logic.And transactions

Consider that i have 3 Tables A,B,C 考虑我有3个表A,B,C

1)BOs  : are A_BO ,B_BO ,C_BO
2)Managers :A_M,B_M,C_M
3)DAOs :A_DAO,B_DAO,C_DAO


All write operations of BO are handles by respective Manager. 
EG : Two write into A_BO manager A is always called.

Now for some operations i need to access multiple tables/BO . 现在,对于某些操作,我需要访问多个表/ BO。

For example to insert a record in A i need to check something in table B.  <br>
Write of A is handled by A managed. 



Now the question is can A manager call B_DAO? 现在的问题是,经理可以打电话给B_DAO吗? or should it only call B_MAnager? 还是只应调用B_MAnager? and not access B_DAO? 不能访问B_DAO?

I am confused about which approach should i takes? 我对应该采取哪种方法感到困惑? Some concerns: If manager calls some other manager i cannot put @Transaction Annotation on manager and i will need one more layer on top of Manager then 一些问题:如果经理打电话给其他经理,则我不能在经理上放置@Transaction Annotation,并且我需要在Manager之上再加上一层

I don't see the differences of your DAO layer and manager layer. 我看不到您的DAO层和管理者层的区别。 They seem to have the same responsibility: manage entities. 他们似乎负有相同的责任:管理实体。

On the other hand I miss something like a business layer. 另一方面,我想念诸如业务层之类的东西。 Inside a business logic you will have usecases which need access to more than one entity. 在业务逻辑内部,您将拥有需要访问多个实体的用例。 For example to store a new bill you will have updates on billing data, customer accounts, maybe warehouse stock and lots of other entities. 例如,要存储新的帐单,您将具有帐单数据,客户帐户,也许还有仓库库存以及许多其他实体的更新。 All these updates should occur inside one transaction. 所有这些更新应在一个事务中进行。 Therefore you should see all functionylity defined in your current DAO and manager layer as one persistence layer, that's functionality can only be used inside of transactions. 因此,您应该将当前DAO和管理器层中定义的所有功能视为一个持久层,该功能只能在事务内部使用。 To have one DAO per entity is a common pattern here. 在每个实体上只有一个DAO是一种常见的模式。

Transactions should be triggered by some business layer where the supplied functionality does something usefull in terms of your application logic. 事务应该由某个业务层触发,其中所提供的功能可以根据您的应用程序逻辑做一些有用的事情。 That's also the point where transaction demarcation and other aspects like permission checking can be implemented. 这也是可以实现事务划分和其他方面(如权限检查)的地方。

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

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