在工作单元模式中共享代码
这是一个一般性问题。我正在使用工作单元模式设计一个系统。是否有任何已建立的模式列出了如何以单元可测试的方式在多个工作单元之间共享逻辑?
这是一个更具体的场景:
有一个 PurchaseOrder
工作单元1 ->提交 PO 供审批
工作单元2 ->批准或拒绝 PO 并将其发送回提交者
两个工作单元共享相同的代码,例如:
ShareLogic1 ->用户需要有权访问 PO
SharedLogic2->将最后的操作记录到 PO
我可以使用什么模式来在多个工作单元之间共享此类逻辑。虽然继承可以解决这种情况下的问题,但我不想使用继承,因为它并不适合所有情况。
This a general question. I am designing a system using the Unit of Work pattern. Are there any established patterns which lays out how to share logic between multiple units of work in a unit testable way?
Here is a more concrete scenario:
There is a PurchaseOrder which
UnitOfWork1 -> submits PO for approval
UnitOfWork2 -> approves or denies PO and sent it back to submitter
Both Unit of works shares same code such as:
ShareLogic1 -> User needs to have access to PO
SharedLogic2 -> Record the last action to PO
What pattern(s) can I use where such logic can be shared between multiple units of work. Though inheritance can solve the problem in this case, I don't want to use inheritance as it won't fit in every case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将该逻辑放入一个类中,并让两个工作单元都可以访问它。这两个示例似乎都属于 PurchaseOrderRepository 类。使用控制反转你可以模拟它。
Put that logic in a class and let both units of work have access to it. Both examples seem to belong to a PurchaseOrderRepository class. Using inversion of control you can mock it.