Parent/child question

Parent/child question

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


Discord posted on Friday, May 12, 2006

First of all let me say that I am very new to CSLA but it seems very cool.
Let me see if I can phrase my question properly. I have to create a Parent/Child set of objects.
So for the parent I was going to create a shared function to call from the UI that would instantiate the parent object and load the data from the database. Like I've seen in the book.
The question I have is do I need to do the same thing with the child object? Since when I'm loading the data into the instantiated parent object I'm already on the remote server it seems I could just create the child without a shared factory method. Or does that break the idea of CSLA?
I hope this makes sense and thank you.

RockfordLhotka replied on Friday, May 12, 2006

You certainly could just expose a Friend/internal scoped constructor on your child classes. As you can see in Chapter 7, I prefer to be consistent and use a factory scheme for all my objects, but that's really personal preference.

The factory method is pretty much required for any root object, otherwise you can't interact properly with the data portal. But for non-root objects (within reason) I suppose you could say anything goes.

Discord replied on Monday, May 15, 2006

Consistency... I didn't think about that. Seems like a good reason to use the factory functions for non-root objects too. Thank you for the reply and great framework.

Copyright (c) Marimer LLC