views:

74

answers:

3

Hello All,

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). 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. 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. I am just wondering if anyone has any advice on how to model this requirement.

A: 

It sounds like Transfer isn't an object, it's a workflow. Look at Windows Workflow Foundation... Here's a good QuickStart example.

Rex M
I have been looking over the WF4 documentation. It seems that this would be a perfectly acceptable way to go about the approval/review process. There are some good examples from Microsoft that show almost exactly what I am trying to do.
Aver
@Aver great! If this or another answer solves your problem, please indicate it by clicking the large checkmark next to the answer.
Rex M
Workflow is a tool that does not automagically solve design issues. Hence - down vote.
Arnis L.
A: 

If you think about the responsiblity of the Transfer object, it is to manage the Transfer of an Employee to another Office. I would design this with the Transfer object being separate from both the Employee and the Office, but having a reference to each. 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. It is not bad design for the Transfer object to have references to the other objects. The relationship between Transfer and Employee (and also Transfer and Office) in this case a "uses" relationship.

EchoCoder
My next question would be around persisting the change. So my transfer object has Transfer.Employee and some Finalize() method that does the transfer (updates the employee object). At this point is it as simple as getting the employee object from the Transfer object and attaching it to my context?
Aver
+3  A: 

You could treat the transfer as a completely separate object - an EmployeeTransfer.

As a minimum, it would contain the following data: 1. The unique identifier of an Employee. 2. The unique identifier of a Transfer From Office. 3. The unique identifier of a Transfer To Office. 4. A Status indicator for the progress of the Transfer.

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.

The only prerequisite for this solution is that the Employee and the Offices must exist prior to the creation of the Transfer.

MrUpsideDown
This is the way I would go. By explicitly defining this as a **business concept**, it fits well with DDD. It also gives you the option to persist these *Transfer* objects - giving you an **audit trail** for little extra effort.
Vijay Patel