473,503 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

EventArgs design question

I have a hierarchy of message classes. Many times when messages are
created/received by a class, an event is generated to let the outside
know. Also, the message is passed along when raising the event.

To follow the .NET event guidelines, each message class therefore needs
its own EventArgs derived class to represent it. The problem is that
these EventArgs classes do not add anything of value themselves. There
is no additional event data they can contain other than the message
itself.

So I was thinking about replacing the message classes with the EventArgs
classes. In other words, put all of the properties and methods that are
in the message classes into the EventArgs classes. Since the message
classes are small and immutable, I don't see any negative side-effects
from doing this.

The problem is that there are times when you need a message class object
that is not the result of an event. In those situations, you would be
working with an EventArgs object when no event has occurred. That seems
a little strange.

This is all a matter of design and convention. Seems like in my desire
to follow guidelines, I'm lead to a compromise that's less than optimum.

At any rate, I was happy to see the generic EventHandler<TEventArgs> in
the latest version of the .NET Framework. I can see reasons against
this, but a generic EventArgs<TEventData> class might come in handy
here, too.
Jan 13 '06 #1
3 4652
Hi Leslie,

The EventArgs class was designed to be inherited. It doesn't contain any
public data. When you inherit it, you provide the derived class with your
own data. In your case, your Message class would be the data.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Leslie Sanford" <ja**********@BiteMeHotmail.com> wrote in message
news:Pu********************@comcast.com...
I have a hierarchy of message classes. Many times when messages are
created/received by a class, an event is generated to let the outside know.
Also, the message is passed along when raising the event.

To follow the .NET event guidelines, each message class therefore needs
its own EventArgs derived class to represent it. The problem is that these
EventArgs classes do not add anything of value themselves. There is no
additional event data they can contain other than the message itself.

So I was thinking about replacing the message classes with the EventArgs
classes. In other words, put all of the properties and methods that are in
the message classes into the EventArgs classes. Since the message classes
are small and immutable, I don't see any negative side-effects from doing
this.

The problem is that there are times when you need a message class object
that is not the result of an event. In those situations, you would be
working with an EventArgs object when no event has occurred. That seems a
little strange.

This is all a matter of design and convention. Seems like in my desire to
follow guidelines, I'm lead to a compromise that's less than optimum.

At any rate, I was happy to see the generic EventHandler<TEventArgs> in
the latest version of the .NET Framework. I can see reasons against this,
but a generic EventArgs<TEventData> class might come in handy here, too.

Jan 14 '06 #2
As an aside - I use the following quite a bit:

[System.ComponentModel.ImmutableObject(true)]
public class SimpleEventArgs<T> : EventArgs {
private readonly T _value;
public T Value { get { return _value; } }
public SimpleEventArgs(T message) {
_value = message;
}
}
public event EventHandler<SimpleEventArgs<string>> SomeEvent;

This allows me to include a single, strongly typed, object (message) in my
event definition at no cost in terms of typing.

Marc

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
Hi Leslie,

The EventArgs class was designed to be inherited. It doesn't contain any
public data. When you inherit it, you provide the derived class with your
own data. In your case, your Message class would be the data.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Leslie Sanford" <ja**********@BiteMeHotmail.com> wrote in message
news:Pu********************@comcast.com...
I have a hierarchy of message classes. Many times when messages are
created/received by a class, an event is generated to let the outside
know. Also, the message is passed along when raising the event.

To follow the .NET event guidelines, each message class therefore needs
its own EventArgs derived class to represent it. The problem is that
these EventArgs classes do not add anything of value themselves. There is
no additional event data they can contain other than the message itself.

So I was thinking about replacing the message classes with the EventArgs
classes. In other words, put all of the properties and methods that are
in the message classes into the EventArgs classes. Since the message
classes are small and immutable, I don't see any negative side-effects
from doing this.

The problem is that there are times when you need a message class object
that is not the result of an event. In those situations, you would be
working with an EventArgs object when no event has occurred. That seems a
little strange.

This is all a matter of design and convention. Seems like in my desire to
follow guidelines, I'm lead to a compromise that's less than optimum.

At any rate, I was happy to see the generic EventHandler<TEventArgs> in
the latest version of the .NET Framework. I can see reasons against this,
but a generic EventArgs<TEventData> class might come in handy here, too.


Jan 14 '06 #3
Minor note: param name "message" was unintentional (leftover from
refactoring); should be value.

Marc
Jan 14 '06 #4

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

Similar topics

5
674
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of...
2
2543
by: ZAky | last post by:
Why do I get a System.NullReferenceException for this script? I added the following script to a simple form with a button. <Script> public event EventHandler DoThis; static void Main() {...
8
4524
by: Phill | last post by:
All the event handlers seem to pass an Object and an EventArgs object. If the event doesn't need this info why pass them anyway? It is inefficient.
2
8312
by: David Lozzi | last post by:
This script is in the code-behind. This is a repost of a reply in "Name 'IsNumeric' is not declared??'. I wanted to post it under a different subject. Type 'EventArgs' is not defined at Sub...
17
2673
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
5
1029
by: SamSpade | last post by:
I'm working on something the wizard converted from VB6. I have some event handlers that use eventArgs and some that use e. It may be simply that the wizard used eventArgs and the IDE uses e....
2
2322
by: Bob | last post by:
Hi, I'm still new to asp.net and i would like to understand this: "Source As Object, e As EventArgs" <script runat="server"> Sub button1(Source As Object, e As EventArgs) p1.InnerHtml="You...
19
3133
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design...
4
2158
by: Frankie | last post by:
The .NET Framework provides us with built-in event handlers: System.EventHandler and the generic System.EventArgs<TEventArgs> It appears that those built-in event handler delegates are just a...
0
7198
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
7072
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
7319
jinu1996
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...
0
7449
tracyyun
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...
0
5570
agi2029
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,...
1
4998
isladogs
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...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
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...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.