events in classes

  • Thread starter Thread starter Andy B.
  • Start date Start date
A

Andy B.

I am new to writing events into classes. What sort of events would you see
an address class having?
 
Andy B. said:
I am new to writing events into classes. What sort of events would you see
an address class having?

Events are used to indicate that something has happened inside a class. I
don't think that a typical address class would have events.
 
Herfried,

Andy is busy to build a kind of address class, that has beside the data as
well the methods to change that data.
He want to create events around that. What he is doing is in my idea a
little bit unorthodox.
However, got give you the idea why he wants events.

Cor
 
Why is that?

Cor Ligthert said:
Herfried,

Andy is busy to build a kind of address class, that has beside the data as
well the methods to change that data.
He want to create events around that. What he is doing is in my idea a
little bit unorthodox.
However, got give you the idea why he wants events.

Cor
 
Because it is your class, being built for you to use for your purposes, then
the events that should be included are the events that you need in order to
use that class effectively within the application you are building it for.

If you can indicate why you think you might need events in the class, then
someone may be able to suggest what those events should be.

A typical event for that type of class might be the changed event. But if
your application is fully responsible for making changes, then the
application will know when a change has occurred without needing to be
informed through an event. Unless you can describe how you expect to be
using the class, no-one could make any suggestions other than the most
obvious and general.

Andy B. said:
Why is that?
 
I guess since the Address class is managed by other objects and not by
itself then there probably wouldn't really be any events. I know some of the
other classes would have events like AddressAdded event and things like
that.
 
There's no reason the class wouldn't have events, but that is a decision you
need to make as part of the design of the class - the decisions about
exactly what functionality you want to build into a class and make available
to whatever application uses the class.

For instance, a common event for an address class might be a
validation_failed event - every time a property (or certain properties) of
the class is updated the property set procedure could attempt to validate
the item and raise a validation_failed event (providing some description of
the reason for the failure) if it couldn't properly validate the data. If
the application is interested in validation, it listens for the event. If
it's not interested in validation it doesn't include a handler for the
event.

There are many other similar examples. It's just a question of what you
want your class to do. How the class is being 'managed' has nothing to do
with it.
 
Back
Top