[AccessD] Implements vs WithEvents

John W. Colby jwcolby at colbyconsulting.com
Tue Jan 13 18:54:12 CST 2004


Charlotte,

>They have somewhat different purposes.

No, they have completely different purposes.

>Implements allows you to subclass an existing object/class and give it
additional or different functionality, so you can have a class Dog and a
subclass Spaniel that has a property Retriever.

Well... true but not exactly.  My issue with that statement is the term
subclass as you use it.  Yes you are subclassing the original but ONLY the
interface.  IMHO that is almost useless

Implements is an interface ONLY inheritance, i.e. it allows (forces) you to
start with the same public data and method DEFINITION but does not actually
inherit the behaviors (methods) themselves.  I.e. the code that runs in the
class that is being subclassed is NOT inherited into the subclass.

Access' inheritance (interface) is not very useful except as a template kind
of thing.  I find it useless enough that I personally don't bother.  On the
other hand Shamil is a proponent so it must have its uses.

When you move to VB.NET (or any of the other .net languages I believe) TRUE
inheritance is available.  I.e. if you have a method with a thousand lines
of code, when you subclass that object the new object inherits that code as
well as the data.  In our Implements subclassing, you would have to cut and
paste that thousand lines of code into the subclass.  Can you say
maintenance nightmare?

>You can intercept and respond to specific events when they happen in the
object.  Did the Bark event trigger?  WithEvents
lets you find out and respond from another class/object.

Exactly correct.  One of the MAJOR shortcomings of Access / VBA (in fact VB
prior to VB.Net) is that Inheritance is virtually non-existent, and even
worse, objects other than forms don't have a built in class that you can get
at to add functionality directly to.  What WithEvents really does is allow
you to build class wrappers for objects so that you can encapsulate
behaviors (functionality) in your class.  In essence you still have two
objects, the control (or even another class or OCX) and your class, but now
you can put all of the common functionality in your class along with the
event stubs of the control/class/ocx that generates the event.

This does not get you any further down the road towards inheritance, sadly
it simply doesn't appear to be possible in Access / VBA.  But it does
provide a huge step up in encapsulation.

John W. Colby
www.ColbyConsulting.com

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Charlotte
Foust
Sent: Tuesday, January 13, 2004 4:56 PM
To: Access Developers discussion and problem solving
Subject: RE: [AccessD] =function() in .onclick


They have somewhat different purposes.  Implements allows you to
subclass an existing object/class and give it additional or different
functionality, so you can have a class Dog and a subclass Spaniel that
has a property Retriever.  WithEvents allows you to monitor the events
of an object/class.  You can intercept and respond to specific events
when they happen in the object.  Did the Bark event trigger?  WithEvents
lets you find out and respond from another class/object.

Charlotte Foust

-----Original Message-----
From: Robert Gracie [mailto:Subscriptions at servicexp.com]
Sent: Tuesday, January 13, 2004 1:45 PM
To: Access Developers discussion and problem solving
Subject: RE: [AccessD] =function() in .onclick


Hello All,
 Since I'm just learning this type of programming technique I thought I
would ask a question...

  Why not use Implements instead of WithEvents?  My limited understand
of WithEvents is that they will not return functionality unit they (the
event) has completed processing... Since I'm just at the "door" so to
speak with learning how to use and incorporate these new (to me)
programming techniques into my work, I really want to start out using
the "best" technique...


Robert Gracie
www.servicexp.com




More information about the AccessD mailing list