Link to home
Start Free TrialLog in
Avatar of Ryan
RyanFlag for United States of America

asked on

VB.Net Inheritance requiring a reference

Class A,B and C are all in different projects. (N-tier topology for A and B) C is a class with common properties used across many solutions.

Class B inherits Class C
Class A cannot call a method from class C via class B without a reference to class C?

Am I doing this correctly? I wouldn't think everything A needs to know about C would be in B.
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

>>Class A cannot call a method from class C via class B
what do u mean by that?
is it override function in B?
can u give concrete example?
Avatar of Ryan

ASKER

Class C
  public function DoThis() as string
end class C

Class B
  inherits C
  public function AlsoThis() as string
end class B

Class A
  dim test as Class B
  ?test.DoThis
end class A

This will work, but only if I reference both B and C with the project containing A. I was hoping to only reference B.
When you add a reference to B, you also need to add reference to C because it is used by B.
Avatar of Ryan

ASKER

CodeCruiser, thats what I'm seeing. I was hoping there was another way.

I did find another way, which doesn't require the 2nd reference, but requires rewriting the function signatures.  I'm seeing pros and cons to this.

Class C
  public shared function DoThis() as string
  public shared function DoThat() as integer
end class C

Class B
  public shared function DoThis as string
    return C.DoThis
  end function
  public shared function DoThis as integer
    return C.DoThat
  end function
  public shared function AlsoThis() as string
end class B

Class A
  ?B.DoThis
end class A
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ryan

ASKER

With the 2nd way, A doesn't need a reference to C.
It does not need a reference correct but at runtime, A would need access to DLL file containing definition of C or you will get error.