Curious - What is Implements used for

M

Mike

Hi,

Just out of curiousity / desire to learn, can someone explain to me what
Implements is useful for?

The way I read the example, variables were defined in one class, then two
classes that Implement that first class have to define all the properties to
cover those variables - does that mean that the only thing implements does
is save you from having to declare the variables in the other 2 classes?
either the example is too simple, or I'm just missing something.

I guess the reason I ask is I was trying to find a way to define a class for
my charts with a "standard" reaction to events (standard for my particular
app), and then for specific charts override some of those events, and I
stumbled across implements, but I'm not sure if that's what I'm looking
for... and now I'm curious.

Thanks,

mike.
 
N

NickHK

Mike,
The way I use Implements means that you can have a generic variable that is
used for different implentations of the interface.
So, in the example, we know that any varialbe declared as IBarcode will have
the guarateed methods/properties.

'< Class IBarcode >
Private Property Get cbarCode_CodeNumber() As String
'Stub signatures only
End Property

Private Property Let cbarCode_CodeNumber(RHS As String)
'Stub signatures only
End Property
'</ Class IBarcode >>

'< Class cCode2of5 >
Implements IBarCode
Private Property Get cbarCode_CodeNumber() As String
'Code specific to cCode2of5
End Property

Private Property Let cbarCode_CodeNumber(RHS As String)
'Code specific to cCode2of5
End Property
'</ Class cCode2of5 >

'< Class cEAN13 >
Implements IBarCode
Private Property Get cbarCode_CodeNumber() As String
'Code specific to cEAN13
End Property

Private Property Let cbarCode_CodeNumber(RHS As String)
'Code specific to cEAN13
End Property
'< Class cEAN13 >

' VBA code
Dim MyBarCode as IBarCode

Set MyBarCode = New cEAN13
'and/or
Set MyBarCode = New cCode2of5

This works because Implements is a contract that each class will expose all
the same signatures that exist in the Interface.

NickHK
 
R

Robert Bruce

Roedd said:
Hi,

Just out of curiousity / desire to learn, can someone explain to me
what Implements is useful for?

I guess the reason I ask is I was trying to find a way to define a
class for my charts with a "standard" reaction to events

Implements doesn't support events in COM/OLE, only in .NET, so you're out of
luck with this plan, unfortunately.

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top