Subclassing Editable Root objects with child collection

Subclassing Editable Root objects with child collection

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


entara posted on Friday, June 29, 2007

I'm trying to build a core library of CSLA business objects that will be used as a basis ( through inheritance ) for a series of customer-specific application libraries and I am having trouble seeing how to subclass ( or inherit ) an editable root object that has a child collection attached to it.   The child collection would also contain subclassed objects.  The intent is to build the core and then extend it through the application specific library for each customer site. 

The issue I'm having is how to specify the subclassed child collection.  If I leave it defined in the core or base class, it then references the core library's child collection ( and related child objects ).  If I define the collection in the subclassed object it references the correct child collection and related child objects, but I believe that I will then have to move the DataPortal code from the base class to the subclass so that updates are operating on the proper collection.  

Ideally, I would like to leave the definition of the child collection in the base class and then override it somehow... Not sure if this is possible...

Anyway, would anyone have an example of how to inherit an editable root & editable child collection?

Thanks!

 

 

 

JoeFallon1 replied on Saturday, June 30, 2007

I have been having this exact problem for years.

I have never found an adequate solution.

Please let me know if anyone comes up with some new ideas.

Joe

 

DanielVW replied on Monday, July 02, 2007

How about something like this:

Create an interface (eg IChild) that contains an IChildUpdate method (and possibly each DP Method)

In your base class:  When you define the child collection in the base class, define it as a collection containing IChild elements.  In the DataPortal code in the base class call the IChildUpdate method for each child.

The inheriting child class must impliment this IChild interface, and in the IChildUpdate method specify the DataPortal code.

Keep in mind that specifying a child collection in the base class means that you would have to cast the type of the child each time you want to use it.

Copyright (c) Marimer LLC