-
Nov 12th, 2020, 04:54 PM
#1
Thread Starter
Junior Member
Interface inheritance how to get deeper
I'm reading a book vb6 howto program and there is a question where I can't find an answer to.
I need to use inheritance what vb can do poorly you need to use interface inheritance and delegation.
Here is an inheritance hierarchie but I don't understand how you'll get deeper then 1 level.
I've used an example from here :
http://www.vb-helper.com/howto_inter...heritance.html
But I only can implement the employee, student and alumini. I can't implement the employee any further down.
Can I get any deeper in the classes ?
there need to be some trick I know there is composition but I don't think I can use it here.
-
Nov 12th, 2020, 06:33 PM
#2
Re: Interface inheritance how to get deeper
You've been mislead. Implementing multiple interfaces has nothing to do with inheritance.
-
Nov 12th, 2020, 07:01 PM
#3
Thread Starter
Junior Member
Re: Interface inheritance how to get deeper
How can I then implement these classes, or better what would you do.
-
Nov 12th, 2020, 08:23 PM
#4
Re: Interface inheritance how to get deeper
Originally Posted by lamko
How can I then implement these classes, or better what would you do.
I've just uploaded an appropriate example into the CodeBank:
https://www.vbforums.com/showthread....ple-Interfaces
One mistake one can easily make is, reading these Graphs in the "wrong direction".
(the arrows might point "kinda backwards", when it comes to "who has to implement what").
cCommunityMember at the top, is the BaseClass (implementing Nothing).
Then, every Level-stage has to implement all the interfaces of the Levels above it
(as e.g. cStaff at Level3, which has to implement the Level2-Interface cEmployee, as well as the Top-Interface cCommunityMember)
HTH
Olaf
-
Nov 13th, 2020, 11:08 AM
#5
Thread Starter
Junior Member
Re: Interface inheritance how to get deeper
Thx, now I have something I can work with.
Lamko
-
Nov 13th, 2020, 12:25 PM
#6
Re: Interface inheritance how to get deeper
Originally Posted by lamko
Thx, now I have something I can work with.
In case you're not entirely sure, you could try to implement (and then post) a few of the Classes I've left out:
- e.g. cFaculty (which sits at the same Level, and should be similar to cStaff)
- and then maybe go even one Level deeper, and implement cTeacher
What's important is, that the Friend Sub Init(...) always contains the "Class-Type one level above it" as its first argument,
followed by the Arguments, which are typical for this concrete Class.
And in case of multiple interfaces, don't forget to define appropriately named Private Members (and later cast to them in Sub Init).
E.g. cTeacher should look something like that:
Code:
Implements cFaculty
Implements cEmployee
Implements cCommunityMember
Private mFaculty As cFaculty
Private mEmployee As cEmployee
Private mCommunityMember As cCommunityMember
Private mSubject1 As String, mSubject2 As String
Friend Sub Init(Faculty As cFaculty, Subject1 As String, Subject2 As String)
'a cast-block for the delegation-members (all from Faculty As cFaculty)
Set mFaculty = Faculty
Set mEmployee = Faculty
Set mCommunityMember = Faculty
'cTeacher-specific Property-Var-inits
mSubject1= Subject1
mSubject2= Subject2
End Sub
That said, in my Demo there's a Copy&Paste-mistake I made, in the Init-function of cStaff...,
which should (after correction) - better look like this:
Code:
Implements cEmployee
Implements cCommunityMember
Private mEmployee As cEmployee
Private mCommunityMember As cCommunityMember
Private mJobDescription As String
Friend Sub Init(Employee As cEmployee, JobDescription As String)
Set mEmployee = Employee
Set mCommunityMember = Employee
mJobDescription = JobDescription
End Sub
In the posted Code in the CodeBank-Demo, what I've marked blue above,
was typed there as cCommunityMember... which works as well, but doesn't enforce the Hierarchy-dependency properly over the ClassType.
Olaf
-
Nov 15th, 2020, 05:12 PM
#7
Thread Starter
Junior Member
Re: Interface inheritance how to get deeper
This sentence did it for me :
What's important is, that the Friend Sub Init(...) always contains the "Class-Type one level above it" as its first argument,
Found this site which explains friend well : https://www.techrepublic.com/article...eyword-in-vb6/
Thx
Last edited by lamko; Nov 15th, 2020 at 06:01 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|