473,320 Members | 1,799 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,320 software developers and data experts.

Some help designing a class for a C# beginner!

I've been writing code in VB and VBScript for several
years and I'm finally caving in to .net! I've decided to
work with C# as I've always understood the basic concepts
of C/C++ but never gained much experience in writing
actual code.

I'm trying to work out the best way to implement a class
to meet the following requirements.

I have three types of object, lets call them Object1,
Object2 and Object3. Each of these has their own unique
values (i.e. Object1.Name, Object2.Name,
Object3.Location) but there is also a set of
relationships where an Object1 can contain one or more
Object2's and each Object2 could contain one or more
Object3's. It's like a treeview hierarchy.

Basically, I want to work out the best way to implement
this in a manner that the relationships between the
objects would be easy to manange. I'd also like to be
able to iterate through all of the objects belonging to
another object. For example, for a particular instance
of Object2, I'd like to list each related Object3 -
something like foreach(Object3 someObject in myObject2).

I hope I've explained that well enough. In short, I need
to model some hierarchical data and I want to be able to
iterate through it quickly and easily.

Thanks in advance,
Mark.
Nov 16 '05 #1
3 1156
Use a private array or arraylist to hold ref to each child object. Did you
mean something else?

--
William Stacey, MVP

"Mark" <mt*************@hotmailspammenot.com> wrote in message
news:0c****************************@phx.gbl...
I've been writing code in VB and VBScript for several
years and I'm finally caving in to .net! I've decided to
work with C# as I've always understood the basic concepts
of C/C++ but never gained much experience in writing
actual code.

I'm trying to work out the best way to implement a class
to meet the following requirements.

I have three types of object, lets call them Object1,
Object2 and Object3. Each of these has their own unique
values (i.e. Object1.Name, Object2.Name,
Object3.Location) but there is also a set of
relationships where an Object1 can contain one or more
Object2's and each Object2 could contain one or more
Object3's. It's like a treeview hierarchy.

Basically, I want to work out the best way to implement
this in a manner that the relationships between the
objects would be easy to manange. I'd also like to be
able to iterate through all of the objects belonging to
another object. For example, for a particular instance
of Object2, I'd like to list each related Object3 -
something like foreach(Object3 someObject in myObject2).

I hope I've explained that well enough. In short, I need
to model some hierarchical data and I want to be able to
iterate through it quickly and easily.

Thanks in advance,
Mark.


Nov 16 '05 #2
Mark wrote:
I've been writing code in VB and VBScript for several
years and I'm finally caving in to .net! I've decided to
work with C# as I've always understood the basic concepts
of C/C++ but never gained much experience in writing
actual code.

I'm trying to work out the best way to implement a class
to meet the following requirements.

I have three types of object, lets call them Object1,
Object2 and Object3. Each of these has their own unique
values (i.e. Object1.Name, Object2.Name,
Object3.Location) but there is also a set of
relationships where an Object1 can contain one or more
Object2's and each Object2 could contain one or more
Object3's. It's like a treeview hierarchy.

Basically, I want to work out the best way to implement
this in a manner that the relationships between the
objects would be easy to manange. I'd also like to be
able to iterate through all of the objects belonging to
another object. For example, for a particular instance
of Object2, I'd like to list each related Object3 -
something like foreach(Object3 someObject in myObject2).

I hope I've explained that well enough. In short, I need
to model some hierarchical data and I want to be able to
iterate through it quickly and easily.

Thanks in advance,
Mark.


I would get a good book on object orientation before you start.

Design is everything in .NET. Design your classes to be small (i.e. less
than approximately 300 lines of code) and reuse your code.

By reusing your code (i.e. never write anything twice) you'll actually
be improving the efficiency of your code.

Because everything is JITted (i.e. compiled at runtime) then if you have
routines which are called all the time they need to be in their own
classes.

A typical example of this would be to get the extension from a file name.

If you duplicate code all over the place to get the extension then this
code has to be compiled seperately for each function.

However if your functions call a single function to get the extension
then this only needs to be compiled once. And from that point onwards
your application will be speedy every time it wants to get an extension
of a filename.

Get the idea ? I hope so.

Darwen.
Nov 16 '05 #3
David McClarnon <dm********@ntlworld.com> wrote:
I would get a good book on object orientation before you start.

Design is everything in .NET. Design your classes to be small (i.e. less
than approximately 300 lines of code) and reuse your code.
While small classes are generally good, there's no point in
artificially constraining yourself to about 300 lines of code.
By reusing your code (i.e. never write anything twice) you'll actually
be improving the efficiency of your code.

Because everything is JITted (i.e. compiled at runtime) then if you have
routines which are called all the time they need to be in their own
classes.
What makes you say that?
A typical example of this would be to get the extension from a file name.

If you duplicate code all over the place to get the extension then this
code has to be compiled seperately for each function.
That's an issue of code reuse more than splitting classes artificially
based on size.
However if your functions call a single function to get the extension
then this only needs to be compiled once. And from that point onwards
your application will be speedy every time it wants to get an extension
of a filename.


I don't believe JIT compilation speed is an issue for most programs
beyond the first few seconds of operation.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

3
by: alexhong2001 | last post by:
When design a class, should always make it "derivable" as a base class? Is there really a situation that the designed class not "derivable"? When should make a member "protected"? Only when...
12
by: James Brown | last post by:
Hi all, Having problems designing a template-class. I'll describe my scenario first then show what I've come up with so far: Need a class to provide pointer/array-like access to an area of...
13
by: Charulatha Kalluri | last post by:
Hi, I'm implementing a Matrix class, as part of a project. This is the interface I've designed: class Matrix( )
4
by: Chris F Clark | last post by:
Please excuse the length of this post, I am unfortunately long-winded, and don't know how to make my postings more brief. I have a C++ class library (and application generator, called Yacc++(r)...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.