[dba-VB] VB.Net - Proxy Class

jwcolby jwcolby at colbyconsulting.com
Fri Jul 27 09:49:23 CDT 2007


I have a situation where I want to have a generic status form which updates
progress information for some very similar processes.  In all cases a
process class needs to raise events and the events need to be sunk in the
progress form.  Each event then updates one specific control on the progress
form.

Events:	
Current file	
FileComplete	
FilesToProcess
LinesComplete
Status

My problem is that AFAIK in order to sink events, an object has to be dimmed
WithEvents and the type of object has to be specified.  Thus the progress
form would have to be told in its header that it was working with a specific
class, and thus the progress form is no longer generic.  I know that I can
not use events and simply have the class open an instance of the progress
form directly, and directly manipulate the controls but I would prefer to
have a loosely coupled interface in the process class where it can just
raise events and if there is anyone who cares, it can process those events.

Can I use something like a proxy class where the proxy class knows about
process class and retransmits its events.  The progress form knows about the
proxy class.  Thus the progress form is loaded and passed in a proxy class.
That proxy class has been defined and hard coded to dim a specific object
which sources the events of interest?  

This seems like an inheritance thing for the proxy class.  Design a
ProgressProxy class which has code to source specific named events.  Create
a clsProcessProxy which inherits the ProgressProxy class.  In this class
hard code the object which is the original event source.  Name this object a
generic name so that the object itself can be changed, but the event sinks
never change and simply then call up to the parent (inherited ProgressProxy)
to retransmit the event.


clsProcess > clsProcessProxy inherits ProgressProxy > frmProgress (dims a
clsProcessProxy and is passed in an instance to set its local copy to)

Does any of this make sense?

John W. Colby
Colby Consulting
www.ColbyConsulting.com 




More information about the dba-VB mailing list