born4code
asked on
The "RaiseEvent" in a Class
Does anyone know what this is good for? I have never used this because I can easily just put a function or procedure in my class and call it directly. What specific advantage does the "RaiseEvent" have over a simple function or procedure within a class?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well "RaiseEvent" is a very special thing even in a class.
Actually it is meant to raise your custome events. As FernandoSoto said it is particularly useful in a Control, But elsewhere even in a normal class it is sometimes too good.
As I said it is a way to raise your custom events,So its primary use is to raise your user defined events. Now often we don't really understand the power of Events and we tend to under-utilize the Events.
As you said >>> "I have never used this because I can easily just put a function or procedure in my class and call it directly. What specific advantage does the "RaiseEvent" have over a simple function or procedure within a class"
Yes you can easily put a Function/Procedure but then this Function/Procedure needs to be called by the other class using this class. But in case of events its (well almost) the other way round, now instead of they calling your Function/Procedure you are calling their Function/Procedure. That's the specific Advantage of RaiseEvent.
You understand ??? Say you have a Class MyClass it has some functions and one event.
And say I am using your class, Now it's in my hands when I call your method, I mean when the flow goes to that particular function call the Function in your class will be called, you have no control when. Now suppose you want that at a particular time (event) some code should run in the client calling your class, How'd you do it?? You'll provide with an event and call RaiseEvent so that some code in the client program can be run.
A judicious use of Events/RaiseEvents gives a good class design, A lot of people now a days stress on "Loosely Coupled Architecture". Events/Delagates are the key to such a Design.
Actually it is meant to raise your custome events. As FernandoSoto said it is particularly useful in a Control, But elsewhere even in a normal class it is sometimes too good.
As I said it is a way to raise your custom events,So its primary use is to raise your user defined events. Now often we don't really understand the power of Events and we tend to under-utilize the Events.
As you said >>> "I have never used this because I can easily just put a function or procedure in my class and call it directly. What specific advantage does the "RaiseEvent" have over a simple function or procedure within a class"
Yes you can easily put a Function/Procedure but then this Function/Procedure needs to be called by the other class using this class. But in case of events its (well almost) the other way round, now instead of they calling your Function/Procedure you are calling their Function/Procedure. That's the specific Advantage of RaiseEvent.
You understand ??? Say you have a Class MyClass it has some functions and one event.
And say I am using your class, Now it's in my hands when I call your method, I mean when the flow goes to that particular function call the Function in your class will be called, you have no control when. Now suppose you want that at a particular time (event) some code should run in the client calling your class, How'd you do it?? You'll provide with an event and call RaiseEvent so that some code in the client program can be run.
A judicious use of Events/RaiseEvents gives a good class design, A lot of people now a days stress on "Loosely Coupled Architecture". Events/Delagates are the key to such a Design.
I hope this was of some help.