ProjectResources Assign Method vs. ProjectResource Assignment Module

ProjectResources Assign Method vs. ProjectResource Assignment Module

Old forum URL: forums.lhotka.net/forums/t/7302.aspx


nhwilly posted on Sunday, July 19, 2009

When I look at the functionality provided by the Assignment Module to assign a Resource to a Project, the purpose seems very similar to the Assign method in the ProjectResources collection.

I am sure I'm missing something, and I know how each one works (basically), but I don't know why ProjectResources wouldn't just use the Assignment module via the ProjectResource to add one to the list.

What am I missing about this? 

Was this just a variation for the purposes of demonstrating in the sample?

I feel like I'm missing something.

Thanks in advance.

RockfordLhotka replied on Sunday, July 19, 2009

It is a somewhat contrived example. But at the same time, the overall idea is to illustrate how to implement a many:many relationship between objects.

The classic example is doctor:patient. A doctor has many patients, and a patient may have many doctors.

In a database this is a M:M relationship, usually implemented with three tables: Doctors, Patients and DoctorPatient.

But in an object model that simplistic data-centric view is insufficient. Objects are designed around behavior, and the data model doesn't really reflect behavior, just static relationships.

In an object model, a doctor has a list of relationships to patients. A doctor doesn't own patients - slavery is illegal in most of the world. And a patient doesn't own a doctor for the same reason.

So a doctor object would have a collection of PatientRelationship objects or PatientVisit objects or something that reflects the user scenario the objects are serving.

Similarly, a patient object would have a collection of DoctorVisit objects or something like that.

nhwilly replied on Sunday, July 19, 2009

Thanks for the quick reply, Rocky.

I guess I worded my question ambiguously. (Actually I used to write medical software, so your example made me laugh.)


What I was really asking is that the behavior of creating a ProjectResource from a Project and a Resource by using the Assignment module makes great sense (I've been reading Larman).


But it looks to me like the exact same behavior is being duplicated in the Assign method of a ProjectResources collection.


Don't they both add a resource to a project? If so, why have both? Or am I totally missing something?


BTW, I have one whole monitor in landscape mode dedicated to a two-up display of your book's PDF. Works great!

RockfordLhotka replied on Sunday, July 19, 2009

At the database level they do both add a resource to a project, yes.

 

But at an object level the relationships are different, and the data surrounding those relationships could be different. In most cases the data surrounding the relationships would probably be different, because the usage scenarios would be different.

 

If they really are the same, and the available data is the same, then the data access code could be consolidated.

 

Rocky

nhwilly replied on Monday, July 20, 2009

As usual, you have cleared things up.

 

I will say that I am still trying to shake the relational overtones to my thinking.  I did Smalltalk in the late 80's and we were much more concerned with inheritance of attributes and behavior than with reusable behavior.  Of course, "Hello, wolrd!" was 5mb when computers were lucky to 32mb to work with.

Copyright (c) Marimer LLC