简体   繁体   English

设计帮助 - 对象修改并保存另一个对象

[英]Design Help - Object modifies and saves another Object

I am having some troubles thinking through a design issue and thought that the community may be able to help point me in the right direction. 我在思考设计问题时遇到了一些麻烦,并认为社区可以帮助我指出正确的方向。 I am modeling an employee management system for my company and have come to a design question that has me stumped. 我正在为我的公司建立一个员工管理系统,并且遇到了一个令我难过的设计问题。

Here is the scenario: 这是场景:

I have an Employee class that employee class has a list of Office objects (where the employee works and has worked). 我有一个Employee类,员工类有一个Office对象列表(员工工作和工作的地方)。 I have a requirement to create the ability to transfer an employee between offices. 我需要创建在办公室之间转移员工的能力。 There is some extra overhead for the transfer request (Approvals, Reviews) but at the end the approvals my transfer object should cause the Employee Object Office List to be changed. 转移请求有一些额外的开销(审批,审核),但最后批准我的转移对象应该导致更改员工对象办公室列表。

I am using C#, EF4 and POCO for my objects. 我正在使用C#,EF4和POCO作为我的对象。 I am not sure how to model the transfer object. 我不知道如何建模转移对象。 It is going to be persisted for some time and may not be completed for a few days (approvals have to complete before its allowed to continue). 它将持续一段时间,可能几天内无法完成(批准必须在允许继续之前完成)。 The transfer object needs to know the employee to modify and the new office for the employee. 转移对象需要知道要修改的员工和员工的新办公室。 I feel like it is bad design to make the Employee a child of the Transfer object and modify it there. 我觉得让Employee成为Transfer对象的子代并在那里修改它是不好的设计。 I am just wondering if anyone has any advice on how to model this requirement. 我只是想知道是否有人对如何建模这个要求有任何建议。

You could treat the transfer as a completely separate object - an EmployeeTransfer. 您可以将转移视为完全独立的对象 - EmployeeTransfer。

As a minimum, it would contain the following data: 1. The unique identifier of an Employee. 它至少包含以下数据:1。员工的唯一标识符。 2. The unique identifier of a Transfer From Office. 2.从办公室转移的唯一标识符。 3. The unique identifier of a Transfer To Office. 3.转移到办公室的唯一标识符。 4. A Status indicator for the progress of the Transfer. 4.转移进度的状态指示器。

This is a lightweight object that does not contain any other objects - it references them by unique identifier. 这是一个轻量级对象,不包含任何其他对象 - 它通过唯一标识符引用它们。 When the Transfer is processed, validate that the Employee and Transfer To offices are still valid, then update the Employee Offices collection. 处理转移时,验证Employee和Transfer To办公室是否仍然有效,然后更新Employee Offices集合。

The only prerequisite for this solution is that the Employee and the Offices must exist prior to the creation of the Transfer. 此解决方案的唯一先决条件是员工和办公室必须在创建转移之前存在。

It sounds like Transfer isn't an object, it's a workflow. 听起来像Transfer不是一个对象,它是一个工作流程。 Look at Windows Workflow Foundation... Here's a good QuickStart example. 查看Windows Workflow Foundation ...这是一个很好的QuickStart示例。

If you think about the responsiblity of the Transfer object, it is to manage the Transfer of an Employee to another Office. 如果您考虑Transfer对象的责任,那就是管理将员工转移到另一个Office。 I would design this with the Transfer object being separate from both the Employee and the Office, but having a reference to each. 我会设计这个,Transfer对象与Employee和Office分开,但是对每个对象都有引用。 The Transfer object would probably have an Enum of approval status values and on reaching an end-state (cancelled or final approval) the Transfer object could perform the action of associating the Employee with the new Office and mark itself as completed. Transfer对象可能具有Enum的批准状态值,并且在达到最终状态(取消或最终批准)时,Transfer对象可以执行将Employee与新Office关联并将其自身标记为已完成的操作。 It is not bad design for the Transfer object to have references to the other objects. Transfer对象设计引用其他对象也不错。 The relationship between Transfer and Employee (and also Transfer and Office) in this case a "uses" relationship. 在这种情况下,Transfer和Employee(以及Transfer和Office)之间的关系是“使用”关系。

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

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