Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Implements doesn't work!!! :( 1

Status
Not open for further replies.

JaseUK

IS-IT--Management
Jun 19, 2001
21
GB
Dear all,

I am having a problem writing a few objects in VB. I have created an "interface" class containing a few public routines. I am trying to achieve polymorphism in VB so that each of my classes that "inherit" (using the Inherits statement) some standard functionality from the base class. This explains it better:

Class ITable (My Interface)
- Public Property TableName
- Public Property IDField
- Public Sub Delete
- Public Sub Populate

Class Address (Inherits ITable)
- Public Function Add(val1, val2...)
- Private Sub ITable_Delete()
- Private Sub ITable_Populate()
- Private Property ITable_TableName
- Private Property ITable_IDField

Class Telephone (Inherits ITable)
- Public Function Add(val1, val2...)
- Private Sub ITable_Delete()
- Private Sub ITable_Populate()
- Private Property ITable_TableName
- Private Property ITable_IDField

etc etc etc...
BTW: Add is implemented separately and not as part of the interface as its parameters change each time - but this is simply the specialisation of each class. The Delete and Populate methods have basically the same functionality in each.

My Problem: BASICALLY at design-time I cannot access the properties or methods that are inherited from the ITable base class. EG:

Dim objTest as ITable
Set objTest = New Address
objTest.Add(val1, val2...) ' <- NO PROBLEM
objTest.Populate ' <- PROBLEM! It says method does not exist
objTest.TableName ' <- SAME PROBLEM!!

What am I doing wrong!???

TIA,
Jason
 
Email me classes.



Wil Mead
wmead@optonline.net

 
Actually the answer is simple.... in your &quot;child&quot; classes your Add function is public so it works. But you have no public declaration for the other properties. Yes I know it's public in ITable, but if it's not public in the &quot;child&quot; classes and your object is of that type you won't be able to see it.
 
The Implements creates an interesting model. One that demonstrates the Base/Child relationship rather well in fact. You gain the ability to assign the derrived class to an object of the base class matching the basic OOP principles.

Each one of the Base Class's Public members are redefined in the child as Base_Member. When the object is referenced through the Base classes type, the base_member child members get fired. In these members you must make the connection between base and child objects. This is why I say that the Implements statement illustrates the model better than my style. In order to involve the base object in this definition, you must create one in the child. Unlike some other languages, this is not AutoMagic.

In defining the derrived class you decide how the methods relate.

Below I've related my observations of classes using the Implements Statement.
[tt]
Class ITable (My Interface)
- Public Property TableName
- Public Property IDField
- Public Sub Delete
- Public Sub Populate

Class Address (Inherits ITable)
- Private ITable Embedded Object
- Public Function Add(val1, val2...)
' The following fire when accessed thru Address or Variant object

- Public Property TableName
-- Relays request to Base Class using embedded object
- Public Property IDField
--Relays to embedded object
- Public Sub Delete
--Overrides Base Class action by not using the embedded base object and defining its own immplementation
- Public Sub Populate
--Overrides Base Class action

' the following fire when accessed thru Objects with type ITable. Each simply calls the corresponding child iplementation. Sometimes A little intervention is needed to adjust parameter types.

- Private Property ITable_TableName
- Private Property ITable_IDField
- Private Sub ITable_Delete()
- Private Sub ITable_Populate()
[/tt]

When Building the child class I've found it easiest to desgin the child members to handle almost everything in way of processing. Doing this renders the base object implementation vestigial. They simply contain a redirection to the childs implementation. Finding this slightly confusing I opted to forgo the forced implementations and devised that embed and wrap style, mimiking the actions forced upon me by the Implements statement.

In doing so I loose design time helpers, but those thingies are new to me. I did without them for almost 20 years and really don't miss them... Much. That's not to say that they aren't great. I would also like to add that I'm on the verge of falling for this Implements thingamabob.

Wil Mead
wmead@optonline.net

 
Wil,

Many thanks for the reply and email. I now fully understand how the implements model is designed to work. This has certainly cleared things up and I think I know how to make the necessary changes... No doubt I will get stuck again though...

Jason.
 
No problem, I was dying to figure that bugger out.

Wil Mead
wmead@optonline.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top