Switchable objects?
Old forum URL: forums.lhotka.net/forums/t/3258.aspx
sephus6 posted on Wednesday, July 25, 2007
I have a hierarchy of items that can change at any time. More items can be added to the tree and each item can have a number of different child objects of different types. Currently, each item type can have any number of letters attached to them.
Here's an example:
ItemType1
ItemType2
ItemType2
Letter
Letter
ItemType4
Letter
Item Type5
Letter
Item Type5
Letter
ItemType6
Letter
ItemType4
Letter
Since each item in the tree can have a list of items of any given type I refer to each item as an entity and each entity can have a list of other entities - like this:
EntityList
Entity
LetterList
EntityList
Entity
LetterList
Letter
EntityList
Entity
LetterList
EntityList
Entity
LetterList
Letter
EntityList
.etc
How can I implement this in CSLA?
triplea replied on Wednesday, July 25, 2007
Isn't this something like what's described here? http://forums.lhotka.net/forums/thread/16315.aspx
In any case, 1 way of doing this is to have a list in each of your object of type BusinessBase (or a base class you define). But the problem would be that unless your objects implement an interface or inherit from your base class, you won't be able to call any of their methods (since you won't be able to cast properly...). Also if you have custom non-generic methods you won't be able to call them directly.
By the way are you sure the above model is required and you don't just try to replicate your database structure in your object model?
sephus6 replied on Wednesday, July 25, 2007
What we need is a tree of entities displayed above a grid. You can select an entity in the grid and see the corresponding data below. Each entity has different fields that need to be displayed in the grid. The data is passed to the BO in XML format, as below:
<COMBOS>
<COMBO CMB_ID="000950710" TOOLTIP="000950710">
<COVERAGES>
<COVERAGE CVG_ID="0950690" TOOLTIP="0950690">
<POLICIES>
<POLICY CARRID="00337" POLNBR="X13575071" COV_EFFDT="2003-06-01" TOOLTIP="00337>
<USRS>
<USR CARRID="00337" POLNBR="X13575071" RPT="01" CORR="00" TOOLTIP="00337">
<LETTERS/>
</USR>
<USR CARRID="00337" POLNBR="X13575071" RPT="01" CORR="01" TOOLTIP="00337">
<LETTERS/>
</USR>
</USRS>
<LETTERS/>
</POLICY>
<POLICY CARRID="00337" POLNBR="X13575071" COV_EFFDT="2004-06-01" TOOLTIP="00337">
<USRS>
<USR CARRID="00337" POLNBR="X13575071" RPT="01" CORR="00" TOOLTIP="00337">
<LETTERS/>
</USR>
</USRS>
<LETTERS/>
</POLICY>
<POLICY CARRID="00337" POLNBR="0950690R0" COV_EFFDT="2005-06-01" TOOLTIP="00337">
<USRS/>
<LETTERS/>
</POLICY>
<POLICY CARRID="00337" POLNBR="X13575071" COV_EFFDT="2005-06-01" TOOLTIP="00337">
<USRS/>
<LETTERS/>
</POLICY>
<POLICY CARRID="00337" POLNBR="X13575071" COV_EFFDT="2006-06-01" TOOLTIP="00337">
<USRS/>
<LETTERS/>
</POLICY>
<POLICY CARRID="00337" POLNBR="WCAUTHCLASS" COV_EFFDT="2007-01-01" TOOLTIP="00337">
<USRS/>
<LETTERS>
<LETTER LETTER_ID="583273" LETTER_TYPE="NY07" TOOLTIP="583273"/>
</LETTERS>
</POLICY>
</POLICIES>
<LETTERS/>
</COVERAGE>
</COVERAGES>
<LETTERS/>
</COMBO>
</COMBOS>
I want to convert this structure to business objects in the CSLA framework and pass the entire tree of business objects to the UI. The reason I thought a tree of generic Entity objects was necessary is because the tree can change and new items can be added anywhere in the tree at anytime.
Each Entity has it's own class that uses the IEntity interface. This interface has a type, so when I'm reading the EntityList I can look at the type and now how to cast the object I'm pulling out.
Is there a better way to do this?
Copyright (c) Marimer LLC