Class objects and custom events -
05-06-2011
, 04:37 AM
Hi Everyone,
I am in the process of crafting a few class object into a simple
heirarchy to represent some essential services on a PC. These services
are things are starting of with networking and power. I am writing
these because I find that the existing representations, although
extremely good for the most part, dont provide status change feedback
when the associated hardware / environment changes.
To solve this I am using WMI to listen for various system events, such
as wireless network signal strength change, low power on a battery,
network media disconnect, system hibernation and so on. The system is
being represented by a series of different classes, for example there
is one to represent a NIC. These classes are heirarchically structured
so that at the top you have a 'System', and under that for example
'Networking' and then under that 'NIC's. I hope this all makes sense
so far.
Here is the scenario: There are two ways I can handle the WMI events
inside the class heirarchy that make sense. The first is to 'bubble'
the event up the heirarchy by using custom events until it reaches a
'place' where there is appropriate code to respond to the event. The
second (and my preferred so far) is to have the child object call a
method in the parent object passing its identifier in the method call.
Again I hope this all makes sense so far.
Here is the question: Does anyone have any pro's / con's for handling
things one way or the other. I am at the dev code -> production code
stage and thought I might ask for others experience before committing
to the final design implementation.
Any thoughts are greatly appreciated.
Cheers
The Frog |