×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Is it a good design to have a Class with List of class same class objects

Is it a good design to have a Class with List of class same class objects

Is it a good design to have a Class with List of class same class objects

(OP)
Hi

We have a requirement to create a class like this

Class Bundle
{
int BundleId;
string BundleName;
double NRC;
double ARC;
List<Bundle> BundleList;
int NestedBundleId; //This is the parent BundleId
}

The reason we trying this is we need an xml output like this
<Bundle>
<BundleId>
<BundleName>
<NRC>
<ARC>
<Bundle> //This is based on the nested bundleId
<BundleId>
<BundleName>
</Bundle>
<NRC>
<ARC>
</Bundle>

Can you guys have your opinion on what is the best way to get this structure done as I thought about the circular reference initially, but in this instance there is no circular reference as it just creates new list of bundles

what we doing in c# is
Bundle bundle = new Bundle();
List<Bundle> nestedBundleList= new List<Bundle>
bundle.BundleList = nestedBundleList;

Thanks

RE: Is it a good design to have a Class with List of class same class objects

Let's look at your XML... you have an issue already with it.... you have two NRC/ARC in the root node... Do you mean to have that in the nested node and not the root node?

I would probably just use the XML node writing functions already part .Net.

Yours:
<Bundle>
<BundleId>
<BundleName>
<NRC>
<ARC>
<Bundle> //This is based on the nested bundleId
<BundleId>
<BundleName>
</Bundle>
<NRC>
<ARC>
</Bundle>

What I suspect you want:
<Bundle>
<BundleId>
<BundleName>
<NRC>
<ARC>
<Bundle> //This is based on the nested bundleId
<BundleId>
<BundleName>
<NRC>
<ARC>
</Bundle>
</Bundle>

Walt
IT Consulting for Robert Half
http://roberthalftechnology.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close