Hi
I am designing a class (Q) which will contain provision for dynamic complex
properties.
For example, these properties could be any or all of the following complex
properties:
a) TeamMembers
b) Pets
Furthermore, the above properties may decompose further into sub-properties:
TeamMembers.MemberName
TeamMembers.Age
TeamMembers.Sex
Pets.Species
Pets.PetName
Pets.OwnerName
Pets.Age
The properties and their sub-properies will be defined and stored in
database.
What is the best way to design the Q class so that it can easily access and
assign values to the subproperties?
I've been considering creating a sub-property class called SubProp with the
single member:
Value (type object)
Multiple instances of SubProp can be contained in an indexer property of the
Parent property called ParentProp.
And then multiple instances of ParentProp can be stashed into an indexer
property called CustomPropGroup in the class Q.
The end result is horribly unwieldly though:
For example, the Pets properties shown above would be
Q.CustomPropGroup[2].SubProp[0].Value [Q.Pets.Species]
Q.CustomPropGroup[2].SubProp[1].value [Q.Pets.PetName]
Q.CustomPropGroup[2].SubProp[2].value [Q.Pets.OwnerName]
Q.CustomPropGroup[2].SubProp[3].value [Q.Pets.Age]
It might more intuitive if I overload the indexers to take a string value
for the property name:
Q.CustomPropGroup["Pets"].SubProp["Species"].Value = "Chimpanzee";
Q.CustomPropGroup["Pets"].SubProp["PetName"].Value = "Bubbles";
Q.CustomPropGroup["Pets"].SubProp["OwnerName"].Value = "Michael Jackson";
Q.CustomPropGroup["Pets"].SubProp["Species"].Value = "2";
But as you can see, its still very unwieldly.
Is there a better, more intuitive way or a design pattern solution to this
problem?
Thanks