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
| > |
| > |
| > |
| >
|
|
|