3

Yes, I agree the title suggests my current line of thinking is defective. BUT in the hopes of again arriving at sanity, here's how I got to this sorry state.

The subject object is an Address, and the subject application has hundreds of Employees in three regional offices. In this context, it is useful to treat the (3) addresses as Entity objects, and keep only those three Addresses in the database.

OF course the Employees have employment because the application services thousands of Customers. In this context, it is more useful to treat the Address as a ValueObject.

Now I'd like to have a Party pattern to make the maintenance of common traits that Companies and People have, like...Addresses.

Last factoid - we have a ValueObject class that does things you might expect from value objects (ie, determine equality based on public properties) and an Entity class (equality based on some id if the object is persistent).

So, what to do? I was playing with the following class ideas before I thought I'd ask this and see what kind of answers came back...

class Address : ValueObject, IHaveAddress{
    Line 1 {get;}
    ... etc
    Address {get{return this;}} // this has an awkward smell
}

class EntityAddress : Entity<int>, IHaveAddress{
    Address {get;}
}

interface IHaveAddress {
    Address {get;}
}

class Party : Entity<int> {
    IList<IHaveAddress> _address;
}

Is there any merit to such an idea??

Cheers,
Berryl

ANSWER

Yes, my thinking was defective :-)
The object I was looking for is an Entity, in the context of the model below.

Thanks to IAbstract and this wonderful link

enter image description here

Berryl
  • 12,471
  • 22
  • 98
  • 182
  • just found something interesting: http://blogs.msdn.com/b/cesardelatorre/archive/2011/06/07/implementing-a-value-object-base-class-supertype-pattern-ddd-patterns-related.aspx – IAbstract Jul 05 '11 at 20:41

1 Answers1

2

Does this help: MSDN blogs ... Implementinag a Value-Object Base Class? I think I've found something new to play with ...

Update I'm not sure how much of an answer this is
...I think it is much less confusing to stay with the standard 'Composite' terminology rather than 'Party'. Effectively you have a Company (root), a set of Addresses (or branches) at which many People (or leaves) work.

I'm not sure, yet, just how much value the ValueObject actually has. On the surface, the supertype may well prove useful to compare Address objects. This seems to have a somewhat backwards feel to it, though. That said, it certainly makes more sense in your example to store 1 Address object and add Person as composite objects to the branch Address.

Like I said earlier, I have a personal project in which I will put the ValueObject to work along with some Composite objects to discover it's usefulness. Is your reference to an Entity related to any implementation of Entity Framework? Or is Entity<int> simply intended to reference a record ID number?

IAbstract
  • 19,551
  • 15
  • 98
  • 146
  • Yeah, that's more or less the ValueObject base class I'm referring to in my question, and which I already have. Its useful in that it shows why you want such a base class. Cheers – Berryl Jul 05 '11 at 20:47
  • @Berryl: where is there info on the 'Party Pattern'? – IAbstract Jul 05 '11 at 20:56
  • I first heard of it from [Fowler](http://c2.com/cgi/wiki?PartyPattern) and here is another [mildly interesting link](http://c2.com/cgi/wiki?ContactAndAddressModels) – Berryl Jul 05 '11 at 21:02
  • This [one is interesting too](http://www.cse.fau.edu/~security/public/docs/CRMPattMar05.pdf) – Berryl Jul 05 '11 at 21:09
  • I found those links as well: appears that the 'Party' pattern is actually a 'Composite' ... makes sense. As I mentioned above, I'll probably play with this a bit on a personal project I'm working with. – IAbstract Jul 05 '11 at 21:21
  • I'm giving you the answer for getting me to step back and remember the context I was trying to do this in (Party pattern). See my edit above and let me know if you see this any differently after you work through it a bit. Cheers – Berryl Jul 06 '11 at 02:46
  • No, no, no. Nothing to do with EF. Entity is just a poco class that takes a Type parameter for the Id (here an int), and is the super type for a DDD Entity. If you can't google up a representative class (S#arpArch has a good one) I can share my implementation with you. – Berryl Jul 06 '11 at 02:51