Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Implements

5 views
Skip to first unread message

Stephen J Bement

unread,
Mar 29, 2004, 4:14:58 AM3/29/04
to
IBarfly
Public Sub Drink(Qty as Pints)
End Sub
Public Property Get IsDrunk() As Boolean
End Property

Bubba
Implements IBarfly
Private Sub IBarfly_Drink(Qty as Pints)
End Sub
Private Property Get IBarfly_IsDrunk() As Boolean
End Property

To expose this interface so I can use the following code

Set b as New Bubba

b.Drink 16
If b.IsDrunk Then
b.FallDown
End if

Do I implement the inteface in the IBarfly_Drink method and expose it as
public or do I need a separate Public Sub Drink with the implement ation
therein?

TIA

--
Semper Fi,
Red

Please post to newsgroup only


Jezebel

unread,
Mar 29, 2004, 5:25:02 AM3/29/04
to
Neither. You put the code in the private functions in your Bubba class.
Apart from that your code is fine, apart from the FallDown method: VB
'implements' doesn't support inheritance, so you can't expose public
functions in the Bubba class that aren't in the iBarfly class.


> Bubba
> Implements IBarfly
> Private Sub IBarfly_Drink(Qty as Pints)

.... Code in here


> End Sub
> Private Property Get IBarfly_IsDrunk() As Boolean

..... Code in here
> End Property

"Stephen J Bement" <sp...@null.net> wrote in message
news:et8bu2WF...@TK2MSFTNGP10.phx.gbl...

Larry Serflaten

unread,
Mar 29, 2004, 10:00:13 AM3/29/04
to

"Jezebel" <fro...@mkkk.com> wrote

> Neither. You put the code in the private functions in your Bubba class.
> Apart from that your code is fine, apart from the FallDown method: VB
> 'implements' doesn't support inheritance, so you can't expose public
> functions in the Bubba class that aren't in the iBarfly class.

That does not sound right. A class can expose public methods no
matter how many interfaces it implements. Perhaps you meant,
the meothds of the implemented interface cannot be exposed in
the Bubba class.


> > Bubba
> > Implements IBarfly
> > Private Sub IBarfly_Drink(Qty as Pints)
> .... Code in here
> > End Sub
> > Private Property Get IBarfly_IsDrunk() As Boolean
> ..... Code in here
> > End Property

That part is right. For the Bubba class to know what to do,
the code must be included there. But what is not shown
is the FallDown method that was not a part of the IBarfly
interface:

Public Sub FallDown()
MsgBox "Thud!"
End Sub


> > To expose this interface so I can use the following code
> >
> > Set b as New Bubba
> >
> > b.Drink 16
> > If b.IsDrunk Then
> > b.FallDown
> > End if

To the OP:

This part won't work because the Bubba interface does not
include the IBarfly interface. To get at the IBarfly interface
you have to declare an object of that type:

Dim Bub as Bubba
Dim Bub_As_Fly as IBarfly

Set Bub = New Bubbal
Set Bub_As_Fly = Bub

Bub_As_Fly.Drink 16
If Bub_As_Fly.IsDrunk then
Bub.FallDown
End if

That will work, but you have to use two variables. If
you want your code to work then you have to duplicate
the IBarfly methods, as Public methods of your Bubba
class.

Public Sub Drink(Qty)
IBarfly_Drink Qty
End Sub

Public Function IsDrunk() As Boolean
IsDrunk = IBarfly_IsDrunk
End Sub

Notice I just called on the IBarfly routines for simplicity.
Gerenally that is acceptable, or vice versa, have the
IBarfly methods call on the public routines and put
the actual code in the public routines. Better might be to put
the code in separate subs, and have them both call on it
there. In either case, to expose the IBarfly methods, you
have to declare them in your Bubba class.

Keep in mind the interface is only a contract. The contract
gaurentees that certain methods (defined in the interface)
are gaurenteed to be supported by the class. Public methods
have no gaurentee, you get what is supplied/exposed.
As shown earlier, to take advantage of the interface (contract)
you have to declare a variable of that interface type. If
all you want to do is work with that interface then there
is a shorter version:

Dim Fly As IBarfly
Set Fly = New Bubba

Now you can use Drink and IsDrunk, but you can't get at
the FallDown method in Bubba because the IBarfly interface
does not expose a FallDown method.

HTH
LFS


Jezebel

unread,
Mar 29, 2004, 4:18:32 PM3/29/04
to
Badly worded, you're right. Of course you can add public methods to the
Bubba class. The problem is, if you declare a variable as type Bubba you
won't see the Barfly methods, and if you declare it as Barfly, you won't see
the Bubba methods.


"Larry Serflaten" <serf...@usinternet.com> wrote in message
news:Ot4zL6ZF...@tk2msftngp13.phx.gbl...

0 new messages