Designing Root Object with Child Obects and Child Collection Objects

Designing Root Object with Child Obects and Child Collection Objects

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


silasimmi posted on Sunday, January 28, 2007

Hi,

Being pretty new to the CSLA framework I find myself  lost in design issues. I have designed the architecture of a sizeable application which I am trying to develop. The major business objects are done and so is the database.

I would like to share my ideas and need some help with the code. One issue is that of having a root BusinessBase object with child BusinessBase objects apart from child BusinessListBase objects. How do I implement the save (insert and update) operations in such an architecture? Kindly email me at silaspeter@gmail.com so I could forward the code under discussion.

Cheers to Rocky and the believers.

 

 

RockfordLhotka replied on Sunday, January 28, 2007

So you have an editable root, which directly contains an editable child? Here's the basic pattern:

public class EditableRoot : BusinessBase<EditableRoot>
{
  // ...

  protected override void DataPortal_Update()
  {
      using (SqlConnection cn = ...)
      {
          // ...
          if (_child.IsDeleted)
          {
             if (!_child.IsNew)
                _child.DeleteSelf(this, cn);
            _child = EditableChild.NewEditableChild();
          }
          else if (_child.IsNew)
            _child.Insert()
          else
            _child.Update()
      }
  }
}

public class EditableChild : BusinessBase<EditableChild>
{
  // ...

  private EditableChild()
  {
    MarkAsChild();
  }

  internal void Update(IParent parent, SqlConnection cn)
  {
    // ...
    MarkOld();
  }
}

 

silasimmi replied on Sunday, January 28, 2007

Thank you so much Rocky.

Miracles do happen!!

silasimmi replied on Monday, January 29, 2007

Hi,

Does it make sense to create code for an object that can optionally be used as child or root. Something like being able to switch it between being a child and root. If it does then what would the basic template be.

Something like clubbing the code for Resource Object and the ProjectResource Object and then being able to serialze only the necessary bits based on the context of use.

This could be a completely wrong idea , am I breaking the normalization rules for the BOs? Please give me some pointers. err, I'd be heading down a oneway street ...

Regards,

Silas.

RockfordLhotka replied on Monday, January 29, 2007

The Switchable object concept is discussed briefly in Chapter 7, but it is not something that I encourage. It exists to serve an edge case, but is more often misused due to data-centric design.
 
Rocky
 

silasimmi replied on Tuesday, February 27, 2007

Dear Rocky,

Apologies for being off the radar. Thank you for the pointers. Thanks to the contributions made and found on codeplex.

~Silas~

Copyright (c) Marimer LLC