Critique of Implements keyword 
Author Message
 Critique of Implements keyword

Maybe I'm missing the point here, but polymorphism through the use of the
Implements keyword in VB5 seems to be a little weak to me.

I define a base class to represent records read from a database,
IDataObject.  This class is abstract, with stubs of properties and methods
such as Changed, DataPath, ID, etc...  Now, the actual classes I use
implement the IDataObject interface, but instead of having their OWN
Changed, DataPath, ID, etc... I must define IDataObject_Changed,
IDataObject_DataPath, etc...  If I make these private, then my program
cannot get to them.  If I make them public, it looks stupid:

    Dim Person as New Person

    Person.IDataObject_DataPath = "c:\biblio.mdb"



Thu, 10 Aug 2000 03:00:00 GMT  
 Critique of Implements keyword

'0to60'

I think you are missing the point. Although your method and property
declarations appear as, for example, Private IDataObject_DataPath, they
are, in fact, public declarations of DataPath THROUGH the IDataObject
interface. Therefore you have to obtain a reference to the interface
before accessing its methods.

Dim MyObject As BaseObject
Dim MyDataObject As IDataObject
Set MyObject = New BaseObject
Set MyDataObject = MyObject    'obtains IDataObject interface

Now, MyDataObject.DataPath will go to the Private IDataObject_DataPath.

Regards
{*filter*}


Quote:
>Maybe I'm missing the point here, but polymorphism through the use of
the
>Implements keyword in VB5 seems to be a little weak to me.

>I define a base class to represent records read from a database,
>IDataObject.  This class is abstract, with stubs of properties and
methods
>such as Changed, DataPath, ID, etc...  Now, the actual classes I use
>implement the IDataObject interface, but instead of having their OWN
>Changed, DataPath, ID, etc... I must define IDataObject_Changed,
>IDataObject_DataPath, etc...  If I make these private, then my program
>cannot get to them.  If I make them public, it looks stupid:

>    Dim Person as New Person

>    Person.IDataObject_DataPath = "c:\biblio.mdb"



Fri, 11 Aug 2000 03:00:00 GMT  
 Critique of Implements keyword

Quote:
>'0to60'

>I think you are missing the point. Although your method and property
>declarations appear as, for example, Private IDataObject_DataPath, they
>are, in fact, public declarations of DataPath THROUGH the IDataObject
>interface. Therefore you have to obtain a reference to the interface
>before accessing its methods.

>Dim MyObject As BaseObject
>Dim MyDataObject As IDataObject
>Set MyObject = New BaseObject
>Set MyDataObject = MyObject    'obtains IDataObject interface

>Now, MyDataObject.DataPath will go to the Private IDataObject_DataPath.

I know that this is the only way to do it, but its so counter-intuitive.
Supporting multiple interfaces is not quite the same as true inheritance, I
guess.  I don't want to fill my app with extra lines of code to access the
other interfaces.  Its harder to read.

Since a lack of true inheritance is one of VB's biggest criticisms, I would
assume that it will be addressed in a future version, perhaps even 6.0.  I
think I'll wait until then to re-write my object library.



Sat, 12 Aug 2000 03:00:00 GMT  
 Critique of Implements keyword

'0to60'

The way that VB is using interfaces is the COM way, which is extremely
tight but leads to verbose object names.

For example, suppose a  class CGraphView implements a CCommonView
interface which supports an EstablishLinkage method, I would do the
following

Dim GraphView As CGraphView
Dim GraphView_CommonView As CCommonView

Set GraphView = New CGraphView
Set GraphView_CommonView = GraphView
GraphView_CommonView.EstablishLinkage...

This is obviously verbose, but is quite readable in my opinion. Use of
'With' can obviously help in situations like this.

Regards
{*filter*}



Sun, 13 Aug 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Implements keyword failing *sometimes*

2. Implements keyword

3. Implements Keyword in VBA

4. Doing AbstractFactory using VB's Implements Keyword?

5. Problems with polymorphism in VB5.0 when using keyword Implements

6. 'Implements' keyword

7. VB6 does not maintain binary compatibility with VB5 projects that use Implements keyword

8. Trouble with "Implements" keyword

9. Implements keyword & Events

10. Polymorphism using the Implements Keyword

11. Type Library - Problems with "Implements" Keyword

12. Implements keyword from a .ctl

 

 
Powered by phpBB® Forum Software