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.
LVL 13
RyanProject Engineer, ElectricalAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
You would still need access to the DLL containing Class C so you might as well add a reference to it.
0
 
Meir RivkinFull stack Software EngineerCommented:
>>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?
0
 
RyanProject Engineer, ElectricalAuthor Commented:
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.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
CodeCruiserCommented:
When you add a reference to B, you also need to add reference to C because it is used by B.
0
 
RyanProject Engineer, ElectricalAuthor Commented:
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
0
 
RyanProject Engineer, ElectricalAuthor Commented:
With the 2nd way, A doesn't need a reference to C.
0
 
CodeCruiserCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.