[英]Java code design bidirectional association
This is a question about application code design. 这是有关应用程序代码设计的问题。 Here is my situation:
这是我的情况:
I have a db table named Report which represents the amount of time of work of a user during a given month. 我有一个名为Report的数据库表,它表示用户在给定月份内的工作时间。 I have a DAO to deal with database and a @Service which encapsulates dao's methods and do more stuff with reports.
我有一个DAO来处理数据库,还有一个@Service,它封装了dao的方法并在报告中做更多的事情。
In addition, I have a table Target , to assign goals to the users about their activities (goals can be monthly or yearly). 另外,我还有一个表Target ,可以为用户分配有关其活动的目标(目标可以是每月或每年)。 I have again a DAO and a @Service to use these entities.
我又有一个DAO和一个@Service来使用这些实体。
My question is about design, because i have a bidirectional association between the two services, especially for the following processes: 我的问题是关于设计的,因为我在两个服务之间存在双向关联,尤其是对于以下过程:
I'm refactoring my application and seeing the two beans beans who need each other makes me feel this is not so good... 我正在重构我的应用程序,看到彼此需要的两个bean令我感到这不太好...
Is there a way to design properly this situation (I mean the association between my two services) or should I stay with the bidirectional association? 有没有一种方法可以正确设计这种情况(我的意思是我的两个服务之间的关联),还是应该保留双向关联?
Finally, I solved my problem by making some changes in my ReportDAO and by calling it in my TargetService . 最后,我通过在我ReportDAO一些变化,并通过调用它在我TargetService解决我的问题。 By doing this, I could remove bidirectional association between my two services and have only an unidirectional association.
这样,我可以删除两个服务之间的双向关联,而只有一个单向关联。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.