• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

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.
0
Ryan
Asked:
Ryan
  • 3
  • 3
1 Solution
 
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
 
CodeCruiserCommented:
When you add a reference to B, you also need to add reference to C because it is used by B.
0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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
 
CodeCruiserCommented:
You would still need access to the DLL containing Class C so you might as well add a reference to it.
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now