Results 1 to 7 of 7

Thread: Interface inheritance how to get deeper

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2016
    Posts
    25

    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.

    Name:  Tree.jpg
Views: 248
Size:  13.0 KB

    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.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Interface inheritance how to get deeper

    You've been mislead. Implementing multiple interfaces has nothing to do with inheritance.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2016
    Posts
    25

    Re: Interface inheritance how to get deeper

    How can I then implement these classes, or better what would you do.

  4. #4
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Interface inheritance how to get deeper

    Quote Originally Posted by lamko View Post
    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

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2016
    Posts
    25

    Re: Interface inheritance how to get deeper

    Thx, now I have something I can work with.

    Lamko

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Interface inheritance how to get deeper

    Quote Originally Posted by lamko View Post
    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

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2016
    Posts
    25

    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
  •  



Click Here to Expand Forum to Full Width