473,396 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamic Property groups

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

Nov 16 '05 #1
2 1586
Codex Twin wrote:
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?

I remember myself doing similar things about 4 years ago. As i remember i was doing the following:
You declare a NameValue collection and store your properties as delimited names, eg
CustomGroup = new NameValueCollection();

Q.CustomGroup.Add("Pets.Species", "Chimpanzee")
Q.CustomGroup.Add("Pets.PetName", "Bubbles")

etc...

And then you can read all properties, parsing the name, eg

foreach(string key in Q.CustomGroup.AllKeys) {
string[] s = Split(key);
<do something>
}

where s[0] might be "Pets" and s[1] would be "Species" or "PetName"

That's how you access those properties/subproperties later.

I guess that's the easiest way to build a dynamic set of properties.

Hope it helps,
Andrey aka MuZZy

Nov 16 '05 #2

"MuZZy" <le*******@yahoo.com> wrote in message
news:M4********************@comcast.com...
Codex Twin wrote:
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?
I remember myself doing similar things about 4 years ago. As i remember i

was doing the following: You declare a NameValue collection and store your properties as delimited names, eg

CustomGroup = new NameValueCollection();

Q.CustomGroup.Add("Pets.Species", "Chimpanzee")
Q.CustomGroup.Add("Pets.PetName", "Bubbles")

etc...

And then you can read all properties, parsing the name, eg

foreach(string key in Q.CustomGroup.AllKeys) {
string[] s = Split(key);
<do something>
}

where s[0] might be "Pets" and s[1] would be "Species" or "PetName"

That's how you access those properties/subproperties later.

I guess that's the easiest way to build a dynamic set of properties.

Hope it helps,
Andrey aka MuZZy


Muzzy
Thanks a great deal, mate. I will use your recommendation.
cT
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Hodapp | last post by:
I have seen messages posted about this before, and there is a clear reference to it in the manual, but I have been unable to find a solution. I'm on Slackware 9.1, kernel 2.6.0-test11, using...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
9
by: Bob Alston | last post by:
In 2002, "GrayJay" posted the following code: I did this in a jazz record catalogue to find composers - On a form "frmComposers" Create a text box - txtFindComposer, and add the following sub...
2
by: Zac | last post by:
Alright anyone who has 2c throw it in... I am working through a custom xml serializer and have come upon a conundrum, given our class design. The interface implemented on the base class (base...
4
by: Paul W | last post by:
i have some dynamic controls that i add to a webform (actually, i dynamiclly build a table and add the controls to cells). some of these controls are HtmlSelect controls with the multiple property...
2
by: taras.di | last post by:
Hi everyone, I've been reading up on how to create a drop down box who's context is dynamically produced based on the value of a previous select box. I've read a lot about some of the browsers...
3
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news...
3
by: cwertman | last post by:
I have a question regarding dynamic properties. I have an Object say Account --Id --Prefix --Fname --Lname --Suffix
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.