Another question about object hierarchy

Another question about object hierarchy

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


chrisdot posted on Wednesday, May 05, 2010

Hi all,

I was trying to set up a kind of object hierarchy, and thinking about having a hierarchy of business objects.

Let's take my concrete example, a screen to display the user and its dedicated field. Basically a user can have many different data fields defined and of many different types (like int, bool, strings which will result in different display control on UI side like updowns, checkboxes,etc... in a container control like listbox or datagrid). I give the readonly example, but my question remains the same with an editable object hierarchy.


So what I was first trying to do first was:

//the user BO
public class CreadOnlyUser : ReadOnlyBase<CreadOnlyUser>


//the collection of data fields available for a parent CreadOnlyUser
public class CReadOnlyUserFieldList: ReadOnlyListBase<CReadOnlyUserFieldList, CReadOnlyUserField>


//The abstract base
public abstract class CReadOnlyUserFieldBase: ReadOnlyBase<CReadOnlyUserField>
{
    public int UserFieldID
    {
        get { return GetProperty(...); }
    }

    public string UserFieldLabel
    {
        get { return GetProperty(...); }
    }
}

//The concrete int container
public class CReadOnlyIntUserField : CReadOnlyUserField
{
    public int IntValue
    {
        get { return GetProperty(...); }
    }
}

//The concrete string container
public class CReadOnlyStringUserField : CReadOnlyUserField
{
    public int StringValue
    {
        get { return GetProperty(...); }
    }
}


And of course this didn't work, I had a few problems with the RegisterProperty<> methods and so on... (like a PropertyRegisterNotAllowed exception)

So I searched round the forum and found this discussion and also this one. So the conclusion should be, "I should rather use composition and use interfaces to manage common behavior".

But I can not really imagine how to do that properly. Should the specific data (int./string,etc...) be another child BO of a concrete CReadOnlyUserField container? Something in this mood?

Am I completely wrong? Should I have another approach of those data fields?

Is there somewhere an code example of that case? (or similar)  Any thread I have missed in this forum?

(Im using CSLA 3.8, latest beta)

Thank you,

Christophe

Copyright (c) Marimer LLC