Solved

Multiple Levels of interfaces???

Posted on 1998-11-17
6
142 Views
Last Modified: 2011-09-20
Ok, this would be easy in say C++, but I'm not sure how I do this in VB (I've very new to the language).

Alright the senario is that I have a group of classes that I want to descend from two interfaces.  No problem.

But four of the group I want to decend from two of the classes that descend from the one of the first two interfaces.

So What I want is:

InterfaceFoo
           |
           ClassFoo
                  |
                   ClassBar

InterfaceBlah
            |
             ClassBoo
                    |
                    ClassScream
                    ClassUglyMask

(Gee, I hope that doesn't look to bad in a browser.)  BTW, I'm using MS's notation where a solid line means subclass of, or for VB Implements.  

At anyrate when I put "Implements ClassFoo" in classBar. I get an error with something like (not verbatum since VB just crashed) "ClassBar must implement procedure InterfaceFoo_ClassFoo_ProcedureName of ClassFoo."  Even if I have a procedure named InterfaceFoo_ClassFoo_ProcedureName.

I can't find anything in the help, nor anyone who can help in physical space.  I think I'm miss understanding the notation that VB wants.

Please help,
RobK
Sucking on the juices of feature creep
0
Comment
Question by:rknapp
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:Staplehead
ID: 1445265
rob,

i'm assuming that, since you're designing a non-trivial inheritance relationship between your classes, that you've written OO code in a REAL, ahem - i mean *another*, language.

if so, then what i'm guessing you're trying to do is allow, for instance, CBar to inherit CFoo.  Unfortunately, though, VB doesn't really allow this.  all you can inherit is the interface, not the implementation.

on the other hand, you *could* use delegation to "inherit" CFoo's methods from within CBar.

Try using the class builder utility... you'll see that, to get the diagram you want, what VB does is create an instance of the sub-class as an instance variable of the super-class.  sigh.

Larry
0
 
LVL 1

Author Comment

by:rknapp
ID: 1445266
(My languages of choice are C++ or Java  (well, real Java anyway :) ))

I see your point, and I've used that(delegation) in MS-Access (bleck)
to create rudimentary customer "objects."

What I'm really interested in is the typing, I was hoping to get away
with a real simple object typing scheme:
If typeof blahCurrentBlah is ClassUglyMask Then ...

instead of
  if typeof blahCurrentBlah is ClassBoo Then
    Select Case BlahCurrentBlah.BlahObjectType
    Case rjkClassUglyMask
          Dim TmpMask as ClassUglyMask
          Set TmpMask = BlahCurrentBlah
      <stuff>
    Case rjlClassScream
        Dim tmpScream as ClassScream
        Set tmpScream as ClassScream
        <stuff>
    End select

( It's not so clear in this example, but I need it in what I'm doing and the second option is just plan painful to my hands. :) )

Is there a more elegant way that I'm missing here?

Thanks for your help
RobK
Thinking that if he was writing in Java he could email it
to his mac at home, and it might just work!
0
 
LVL 1

Expert Comment

by:Staplehead
ID: 1445267
yeah, i hear you wrt 100% java, as opposed to 100% "embraced" java...

what is it that you want to do in each of your cases? can you encapsulate the functionality in a method in the interface, implementing it in each class either as a delegate or as its own functionality?  then, you could get away with setting an interface reference, and calling the interface method...

Larry
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Accepted Solution

by:
Mirkwood earned 200 total points
ID: 1445268
What you want is not possible in VB.
VB does not support class inheritence. So you cannot inherited implementations of another class.
VB does not support interface inheritence either. You can implement multiple interface with the implements statement but that is where it ends.
Implements just means that you implement that certain interface.
0
 
LVL 1

Author Comment

by:rknapp
ID: 1445269
Mirkwood --
   Thanks for the answer, it's not what I wanted to hear but what I was expecting. :(

Staplehead --

   I'm working on laboratory software, I've deteremined there are (roughly)  four sample-related and three non-sample related results each with a slightly different (default) calculation that needs to be reported to the user....  Oh WOW!!!  If I get rid of the ISampleRelated and INonSampleRelated and just have all of them implementing IResult that'll solve my problem.  One Interface (well two really there is ApplicationCapsule, but that's not relevant to the discussion) and it'll work right!     Thanks!  Is there anyway I gave give you points as well?   That question gave me a work around for the whole thing!!!!!!!  OH OH The adrenaline is flowing, I gotta go CODE!

Later,
RobK
Jumping up and down in his chair
0
 
LVL 1

Expert Comment

by:Staplehead
ID: 1445270
Yup! you got it!  the sad thing is, that 'workaround' is the way MS says OOD *should* work in VB!

anyway, i disagree with mirkwood, unless i misunderstand his comment... although you can't "inherit" in a classical sense, you can delegate in order to mimic the semantic features of inheritance.  

as far as the points go, you could open another question, or you could ask cust support to rescind the answer.  unless you're willing to open a dummy question, don't worry about it...

Larry

p.s., how'd the coding go?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now