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.Locatio n) 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. 3 1173
Use a private array or arraylist to hold ref to each child object. Did you
mean something else?
--
William Stacey, MVP
"Mark" <mt************ *@hotmailspamme not.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.Locatio n) 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.
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.Locatio n) 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.
David McClarnon <dm********@ntl world.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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 allowing the derived
class(es) directly access it?
Should destructor always be virtual?
Thanks for your comments!
|
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 physical
memory
located on a piece of custom hardware - this memory is only accessible
using machine specific i/o so I want to hide all this in a class. I'm
imagining
|
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( )
|
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) and the Language Objects Library) that I have converted over
to C#. It works okay. However, in the C# version, one has to build
the class library into the generated application, because I haven't
structured this one thing right. I would like to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |