How do I implement common childs for a root (I think)

How do I implement common childs for a root (I think)

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


skaue posted on Wednesday, February 06, 2008

May sound like a stupid title for my question, but english isn't my native language :P

I have various BO types that all share addressinformation. At the moment, all these BO's inherit a common type where I was planning on adding adressinfo. Given that I'm pretty new to CSLA, I haven't fully gotten around how to do this. What I want to achieve is that if two different root BO's have the same address, they will both point to the same address child BO. I've been poking the ProjectTracker's example code, but none of the scenarios match my case.

Could anyone please outline what a good CSLA-approach to this would be? :-)

SomeGuy replied on Wednesday, February 06, 2008

What I have done is create a static class Address and interface IAddress like the Assignment class in PTracker. Then I create the necessary Editable Child BOs like EmployeeAddress and CustomerAddress that implement IAddress.

E

 

skagen00 replied on Wednesday, February 06, 2008

This is a very tricky problem and this is what we do.

Addresses act as immutable objects. That is, 2 Park Avenue Floor 24 NY, NY 10012 is an address. It represents that location. Now, if Joe works there, and changes jobs, it doesn't change the address. It has Joe pointing at a different address.

So, we end up having what is called a ProfileAddress child BO which is a usage of an Address object, much like a ProjectResource is the usage of a Resource in the project tracker demo. Address is an editable root but with only read-only properties and a factory method that contains the information used to create new addresses.

Of course, you need to consider duplicate checking here as well, which is something that I need to consider more deeply myself. There were certain products out there such as Melissa Data which I kind of drool at because they help provide the DPV - kind of a unique ID for an address, help clean up the address, assign the zip-4 plus various other information. But too expensive at this stage.

Good luck,

Chris

 

skaue replied on Wednesday, February 06, 2008

skagen00:

Addresses act as immutable objects. That is, 2 Park Avenue Floor 24 NY, NY 10012 is an address. It represents that location. Now, if Joe works there, and changes jobs, it doesn't change the address. It has Joe pointing at a different address.


Yup. Thats what I want to achieve. We already use a seperate DAL (Nhibernate-driven), and I will be able to lookup addresses based on all its common properties (street, postcode, contry, etc) and if its already there, reuse it, otherwise create it.
At first glance, both solution proposed so far seems applicable.
skagen00:

Good luck,



Thanks. I need it! ;-)

Copyright (c) Marimer LLC