advice on structuring business objects

advice on structuring business objects

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


Helen W posted on Saturday, November 24, 2007

I have an application that has the following candidate BOs:

  1. Organizations. Each organization can have 0 -- n Persons associated with it, and each associated Person can have 0 -- n Roles within the Organization. Thus it seems reasonable to have an OrganizationList: subclassing EditableRootListBase, comprising Organization objects. Each Organization object will have a child PersonList comprising Persons, and each Person in this list will have a RoleList.
  2. Persons. Similarly the app needs a PersonList subclassing EditableRootListBase, and each Person object will have a child OrganizationList, comprising Organizations, and each Organization in this list will have a RoleList for the 0 -- n relationship between OrganizationPersons and Roles.
  3. To make matters more complicated, there is a Members entity, each of which can be either a Person or an Organization.
  4. Clearly the child lists for an Organization (i.e. its PersonList with its child PersonRoleList) and for a Person (i.e. its OrganizationList with its child Organization RoleList) are different views on the same underlying database tables. Is there an elegant way to make sure that if, when editing a Person and an Organization is added to that Person, that the Organization's PersonList automatically gets updated too? Is there a better way to structure all this?

Any suggestions gratefully appreciated.

Helen


dean replied on Saturday, November 24, 2007

Hi Helen,

Rocky et. al. would normally advise you to step back and work up a list of use cases before planning out your objects like this. Rather than create fewer multi-purpose objects, create specific objects for specific use cases. This will usually answer some of your questions about relationships and such.  Don't assume that you need to maintain a complicated object graph unless your use cases demand it.

Regarding point 4 CSLA does not automatically provide the updates to objects since this is basically a UI issue. You should take a look at Petar's Active Objects for CSLA : http://csla.kozul.info/

Good Luck!

Dean

Plowking replied on Tuesday, November 27, 2007

You also have circular references there, with your person object's collection of organisations, and organisation objects collection of people!

Consider that in your application its unlikely you'll be able to edit your parent collection objects, their children collections and the grand children objects simultaneously.

use case suggestions would be

Get a list of Organisations (read only list of organisations)

Add a user to an organisation (business base of User, probably with a collection of organisation IDs as property)

View an organisations users (read only list of User, where you accept organisation id as a criteria)

Assign a user to an organisation role (your editable user should have an editable list of organisation roles)

This is perhaps over simplified, but generally its unlikely you'll need an editable root collection, and your business objects may have several editable collections, but are less likely to have editable collections of collections! Check out project tracker sample application for examples of implementation.

Helen W replied on Tuesday, November 27, 2007

I agree with both of you. I am currently building OrganizationList and PersonList objects subclassing ReadOnlyListBase, following what Rocky did in the Project Tracker example. From these, my users can follow an Organization path that shows the relationships from the organization's view, or a Person path that shows the relationships from a Person's view. I think that will handle their needs nicely.

Thanks!

Helen

 

Copyright (c) Marimer LLC