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

Events and Tree like collections :: Would love to hear you opinion!

Hi everyone,

Here is my problem:

I have the following classes:
- DataNode - this class is designed to hold some data and will be contained
in a tree like data structure DataTree. When DataNode is changed, it raises
"Changed" event. The class has a reference to the DataNode it is being
contained in:
- DataTree - tree like data structure that contains DataNodes; When
DataNodes are inserted, deleted or reodered, DataTree raises the following
events: Inserted, Deleted, Reodered. It also listens to Changed event of the
DataNodes it contains. DataTree subscribes to the Changed events of the
DataNodes when they are added.
- DataTreeCollection - contains multiple DataTrees. It also subscribes to
DataTrees' events

So as you can see, DataTreeCollection ends up with the following events
- DataNode's Changed
- DataTree's Inserted, Removed, Reodered

This way in my application I have to listen to only one instance of
DataTreeCollection, but I still can listen to all events, because all the
players propagate their events to their owners. But a negative side to this
is that the parent of all children will have to have all possible events of
his children...

What do you think about a design like this?
I wonder, if there is better way to do this:

I would love to hear some suggestions or critique
Thank you in advance,
Sasha
Nov 15 '05 #1
3 2002

Hi Sasha,

Thanks for posting in this group.
In your design, how did your event handler distinguish the different
DataNodes that may raise event?
I think you may pass the DataNode's identity in the eventargs. If you do
like this, I think you can create a common event handler for all the
datanodes.(You can do different operations by checking the eventargs)
So it does not need many event handlers for all the children nodes.(As I
think, at design time, you can not know how many children you have, so you
also can not do like this).

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Sasha" <no@no.com>
| Subject: Events and Tree like collections :: Would love to hear you
opinion!
| Date: Wed, 5 Nov 2003 17:47:42 -0800
| Lines: 37
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <OV**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups:
microsoft.public.dotnet.general,microsoft.public.d otnet.languages.csharp,mic
rosoft.public.dotnet.languages.vb
| NNTP-Posting-Host: filenet-gw.filenet.com 198.3.8.1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.csharp:197052
microsoft.public.dotnet.languages.vb:154069
microsoft.public.dotnet.general:114539
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi everyone,
|
| Here is my problem:
|
| I have the following classes:
| - DataNode - this class is designed to hold some data and will be
contained
| in a tree like data structure DataTree. When DataNode is changed, it
raises
| "Changed" event. The class has a reference to the DataNode it is being
| contained in:
| - DataTree - tree like data structure that contains DataNodes; When
| DataNodes are inserted, deleted or reodered, DataTree raises the following
| events: Inserted, Deleted, Reodered. It also listens to Changed event of
the
| DataNodes it contains. DataTree subscribes to the Changed events of the
| DataNodes when they are added.
| - DataTreeCollection - contains multiple DataTrees. It also subscribes to
| DataTrees' events
|
| So as you can see, DataTreeCollection ends up with the following events
| - DataNode's Changed
| - DataTree's Inserted, Removed, Reodered
|
| This way in my application I have to listen to only one instance of
| DataTreeCollection, but I still can listen to all events, because all the
| players propagate their events to their owners. But a negative side to
this
| is that the parent of all children will have to have all possible events
of
| his children...
|
| What do you think about a design like this?
| I wonder, if there is better way to do this:
|
| I would love to hear some suggestions or critique
|
|
| Thank you in advance,
| Sasha
|
|
|

Nov 15 '05 #2
Hello Jeffrey,

Thank you very much for your answer. You were right about passing DataNode's
identity in Custom EventArgs, and that's exactly what I do. But here is a
bit more of info about my class hierarchy.

1. abstract class TrackItem
2. class Requirement : TrackItem
3. class Note : TrackItem
4. class TrackItemCollection : TrackItem - this collection contains
TrackItems. So we have a recursive data structure.
5. class Track
{
TrackItemCollection coll1, coll2
}
6. class TrackCollection - contains all the tracks
7. TEDataSet - contains TrackCollection and other collections

Now, let's talk about events, all TrackItems implement a TrackItemChanged
event; TrackItemCollection also implements TrackItemAdded, TrackItemRemoved,
TrackItemsReodered events.

Every time I add a TrackItem to the TrackItemCollection, I subscribe to
TrackItemChanged event, but also I do this:
if(item is TrackItemCollection)
{
((TrackItemCollection)item).ItemAdded += new
GroupEventHandler(Group_ItemAdded);
((TrackItemCollection)item).ItemChanged += new
GroupEventHandler(Group_ItemChanged);
((TrackItemCollection)item).ItemDeleted += new
GroupEventHandler(Group_ItemDeleted);
((TrackItemCollection)item).ItemsReodered += new
GroupEventHandler(Group_ItemsReodered);
}

This way I can propagate my events to very top which in this case is Track.
But let's add Track into TrackCollection. Now we have to make sure that
TrackCollection knows what TrackItemAdded, TrackItemRemoved,
TrackItemsReodered events are, and notifies subscribers about them.

But here what makes it even more fun, TrackCollection is not the root:
TEDataSet is! So now we have to do the same thing to TEDataSet.

Why do I want to do this? Well, in my UI I want to be able to subscribe to
one object and he will notify me about all events the occur to his children.
In my program I have to draw a TreeView that displays TEDataSet: Using
events I know what to update and when.

What do you think about this? I understand some of this smells, but I
couldn't come up with a better way to do it... That's why I am looking for a
second opinion.

Sasha

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:%2****************@cpmsftngxa06.phx.gbl...

Hi Sasha,

Thanks for posting in this group.
In your design, how did your event handler distinguish the different
DataNodes that may raise event?
I think you may pass the DataNode's identity in the eventargs. If you do
like this, I think you can create a common event handler for all the
datanodes.(You can do different operations by checking the eventargs)
So it does not need many event handlers for all the children nodes.(As I
think, at design time, you can not know how many children you have, so you
also can not do like this).

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Sasha" <no@no.com>
| Subject: Events and Tree like collections :: Would love to hear you
opinion!
| Date: Wed, 5 Nov 2003 17:47:42 -0800
| Lines: 37
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <OV**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups:
microsoft.public.dotnet.general,microsoft.public.d otnet.languages.csharp,mic rosoft.public.dotnet.languages.vb
| NNTP-Posting-Host: filenet-gw.filenet.com 198.3.8.1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.csharp:197052
microsoft.public.dotnet.languages.vb:154069
microsoft.public.dotnet.general:114539
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi everyone,
|
| Here is my problem:
|
| I have the following classes:
| - DataNode - this class is designed to hold some data and will be
contained
| in a tree like data structure DataTree. When DataNode is changed, it
raises
| "Changed" event. The class has a reference to the DataNode it is being
| contained in:
| - DataTree - tree like data structure that contains DataNodes; When
| DataNodes are inserted, deleted or reodered, DataTree raises the following | events: Inserted, Deleted, Reodered. It also listens to Changed event of
the
| DataNodes it contains. DataTree subscribes to the Changed events of the
| DataNodes when they are added.
| - DataTreeCollection - contains multiple DataTrees. It also subscribes to | DataTrees' events
|
| So as you can see, DataTreeCollection ends up with the following events
| - DataNode's Changed
| - DataTree's Inserted, Removed, Reodered
|
| This way in my application I have to listen to only one instance of
| DataTreeCollection, but I still can listen to all events, because all the | players propagate their events to their owners. But a negative side to
this
| is that the parent of all children will have to have all possible events
of
| his children...
|
| What do you think about a design like this?
| I wonder, if there is better way to do this:
|
| I would love to hear some suggestions or critique
|
|
| Thank you in advance,
| Sasha
|
|
|

Nov 15 '05 #3

Hi Sasha,

Thanks for your feedback.
I think I understand your meanning. Your root class can listen to all the
children nodes' events, so it also have to add event handlers for all of
its child controls' events.
Although we can set up the same event handler for the same type of node,
while its children nodes may be of different types, so it has to setup
event handlers for all of its children nodes types.

I did not see the main shortcoming of this design. Only multi-event
handlers for the same event. But this design is different from the normal
model, is a little strange.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Sasha" <no@no.com>
| References: <OV**************@TK2MSFTNGP11.phx.gbl>
<#L**************@cpmsftngxa06.phx.gbl>
| Subject: Re: Events and Tree like collections :: Would love to hear you
opinion!
| Date: Thu, 6 Nov 2003 09:29:50 -0800
| Lines: 152
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <ud**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: filenet-gw.filenet.com 198.3.8.1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:197256
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hello Jeffrey,
|
| Thank you very much for your answer. You were right about passing
DataNode's
| identity in Custom EventArgs, and that's exactly what I do. But here is a
| bit more of info about my class hierarchy.
|
| 1. abstract class TrackItem
| 2. class Requirement : TrackItem
| 3. class Note : TrackItem
| 4. class TrackItemCollection : TrackItem - this collection contains
| TrackItems. So we have a recursive data structure.
| 5. class Track
| {
| TrackItemCollection coll1, coll2
| }
| 6. class TrackCollection - contains all the tracks
| 7. TEDataSet - contains TrackCollection and other collections
|
| Now, let's talk about events, all TrackItems implement a TrackItemChanged
| event; TrackItemCollection also implements TrackItemAdded,
TrackItemRemoved,
| TrackItemsReodered events.
|
| Every time I add a TrackItem to the TrackItemCollection, I subscribe to
| TrackItemChanged event, but also I do this:
| if(item is TrackItemCollection)
| {
| ((TrackItemCollection)item).ItemAdded += new
| GroupEventHandler(Group_ItemAdded);
| ((TrackItemCollection)item).ItemChanged += new
| GroupEventHandler(Group_ItemChanged);
| ((TrackItemCollection)item).ItemDeleted += new
| GroupEventHandler(Group_ItemDeleted);
| ((TrackItemCollection)item).ItemsReodered += new
| GroupEventHandler(Group_ItemsReodered);
| }
|
| This way I can propagate my events to very top which in this case is
Track.
| But let's add Track into TrackCollection. Now we have to make sure that
| TrackCollection knows what TrackItemAdded, TrackItemRemoved,
| TrackItemsReodered events are, and notifies subscribers about them.
|
| But here what makes it even more fun, TrackCollection is not the root:
| TEDataSet is! So now we have to do the same thing to TEDataSet.
|
| Why do I want to do this? Well, in my UI I want to be able to subscribe to
| one object and he will notify me about all events the occur to his
children.
| In my program I have to draw a TreeView that displays TEDataSet: Using
| events I know what to update and when.
|
| What do you think about this? I understand some of this smells, but I
| couldn't come up with a better way to do it... That's why I am looking
for a
| second opinion.
|
| Sasha
|
|
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| news:%2****************@cpmsftngxa06.phx.gbl...
| >
| > Hi Sasha,
| >
| > Thanks for posting in this group.
| > In your design, how did your event handler distinguish the different
| > DataNodes that may raise event?
| > I think you may pass the DataNode's identity in the eventargs. If you do
| > like this, I think you can create a common event handler for all the
| > datanodes.(You can do different operations by checking the eventargs)
| > So it does not need many event handlers for all the children nodes.(As I
| > think, at design time, you can not know how many children you have, so
you
| > also can not do like this).
| >
| > Hope this helps,
| >
| > Best regards,
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: "Sasha" <no@no.com>
| > | Subject: Events and Tree like collections :: Would love to hear you
| > opinion!
| > | Date: Wed, 5 Nov 2003 17:47:42 -0800
| > | Lines: 37
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <OV**************@TK2MSFTNGP11.phx.gbl>
| > | Newsgroups:
| >
|
microsoft.public.dotnet.general,microsoft.public.d otnet.languages.csharp,mic
| > rosoft.public.dotnet.languages.vb
| > | NNTP-Posting-Host: filenet-gw.filenet.com 198.3.8.1
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| > microsoft.public.dotnet.languages.csharp:197052
| > microsoft.public.dotnet.languages.vb:154069
| > microsoft.public.dotnet.general:114539
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | Hi everyone,
| > |
| > | Here is my problem:
| > |
| > | I have the following classes:
| > | - DataNode - this class is designed to hold some data and will be
| > contained
| > | in a tree like data structure DataTree. When DataNode is changed, it
| > raises
| > | "Changed" event. The class has a reference to the DataNode it is being
| > | contained in:
| > | - DataTree - tree like data structure that contains DataNodes; When
| > | DataNodes are inserted, deleted or reodered, DataTree raises the
| following
| > | events: Inserted, Deleted, Reodered. It also listens to Changed event
of
| > the
| > | DataNodes it contains. DataTree subscribes to the Changed events of
the
| > | DataNodes when they are added.
| > | - DataTreeCollection - contains multiple DataTrees. It also subscribes
| to
| > | DataTrees' events
| > |
| > | So as you can see, DataTreeCollection ends up with the following
events
| > | - DataNode's Changed
| > | - DataTree's Inserted, Removed, Reodered
| > |
| > | This way in my application I have to listen to only one instance of
| > | DataTreeCollection, but I still can listen to all events, because all
| the
| > | players propagate their events to their owners. But a negative side to
| > this
| > | is that the parent of all children will have to have all possible
events
| > of
| > | his children...
| > |
| > | What do you think about a design like this?
| > | I wonder, if there is better way to do this:
| > |
| > | I would love to hear some suggestions or critique
| > |
| > |
| > | Thank you in advance,
| > | Sasha
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #4

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

Similar topics

5
by: John Champaign | last post by:
Hi all, I'm working on an educational applet for a child with special needs. He's got a bit of a trick to make my life more difficult... To interact with the applet he needs to click on...
9
by: Marek Mand | last post by:
How to use generated keyboard events? What I am trying here to do is in onkeyup event handler http://www.hot.ee/idaliiga/braggart/createEventTest.htm generate a (shift)TAB keydown so the...
1
by: Sasha | last post by:
Hi everyone, Here is my problem: I have the following classes: - DataNode - this class is designed to hold some data and will be contained in a tree like data structure DataTree. When...
19
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
5
by: JezB | last post by:
I have trawled through the System.Collections namespace looking for some structure that will enable me to represent and manipulate tree structures, as yet to no avail. Of course I can represent...
3
by: Fred Nelson | last post by:
Hi Folks: I have a question about the Page_PreInit and Page_Load events in a web application. My question is: can I count on the Page_PreInit having completed before the Page_Load event...
3
by: Alex | last post by:
What does it mean to "walk the DOM tree"? How do you use it? I hear programmers using this term loosely and I'm not sure what it means. I understand that DOM means Document Object Module and that...
4
by: Sid Price | last post by:
Hello, I have a class of objects (Device) that are managed by another object (Devices) with a collection class (DeviceCollection) inherited from Collections.Hashtable. Each of the Device objects...
0
by: preetkanwal0678 | last post by:
Hello all, Am working on PYTHON +BRANWAVE(framework) Actually am Trying 2 make a tree menu using d both. Am not able 2 target the (.tmpl) files and not getting how 2 make frames in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.