I have an editable root object, and two editable collections, and I can’t determine if the collections should be children of the root object, or root objects themselves.
Working from the use cases, I started out by making them children of the root object as this seemed to make the most sense. However, I need to edit each collection on a separate form, and things became complicated when I needed to do a save. In this configuration, the save needs to be initiated by the root object (which is on a 3rd form), so I guess it would go something like this:
At first I thought this was much to complex for the UI design and reverted to a model where the collection objects were both EditableRootCollections and simply made the Root object responsible for getting a new instance of each one. However, this just produces complexity elsewhere because my root object has properties and methods that rely on a reference to the two collections.
So (he finally gets to the question!), do you think my initial design is OK, and has anyone else written a UI like this? Basically I’m looking for reassurance that this is a reasonable approach.
Thanks in advance.
David
According to your use case this is a perfect candidate for a switchable object, p387 of c# book.
But beware, a switchable object is usually a sign of bad design - but not always. So it's up to you to decide if this fits your requirement.
A switchable object can be instantiated either as a root object or as a child object.
Hope this helps
Thanks for the comment, but I don't see how a switchable object solves my problem. It does give me the option to use either scenario from the UI, but I would then have to write the code to cater for both scenarios. So I would have to deal with both complexities.
I thought switchable objects were used to avoid duplication of code - when you needed to use a similar object in different use case scenarios. This is not really the problem here.
David:I have an editable root object, and two editable collections, and I can’t determine if the collections should be children of the root object, or root objects themselves.
If you _code_ your two editable collections as switchable collections then you'll be able in instantiate your collections as child collections of your editable root object AND you'll also be able to instantiate the collections as _root_ editable collections as well. This way you will be able to call the save method directly from the now _root_ editable collections.
I think your collections should be root objects because the responsibility to update the content of your collections seems to be different from the responsibility of your editable root object. In the case, the responsibility of your root object is to display the collections and not necessarily update the content.
Maybe the solution here would be to have an editable root object with 2 read only collections for display purposes only. Then your 2 root collections for update purposes.
This looks to me like a classic case of 2 distinct reponsibility - I could be wrong though because I don't know the context of your application.
Ummm... on second thoughts...
Maybe what you need is to look at Petar's ActiveObjects at http://csla.kozul.info/. Its an extention to Csla with an extensive _observer_ pattern implementation. It is meant to do something similar to what you are trying do to. I toyed with ActiveObject last year while still in 1.5x, but I havn't done any ActiveObject stuff with Csla 2x.
Hope this helps
guyroch:Ummm... on second thoughts...
Maybe what you need is to look at Petar's ActiveObjects at http://csla.kozul.info/.
Copyright (c) Marimer LLC