Solved

VB.Net Inheritance requiring a reference

Posted on 2013-06-18
7
292 Views
Last Modified: 2013-06-28
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
Comment
Question by:MrBullwinkle
  • 3
  • 3
7 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39258511
>>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
 
LVL 13

Author Comment

by:MrBullwinkle
ID: 39268880
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39271570
When you add a reference to B, you also need to add reference to C because it is used by B.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 13

Author Comment

by:MrBullwinkle
ID: 39272414
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39272543
You would still need access to the DLL containing Class C so you might as well add a reference to it.
0
 
LVL 13

Author Comment

by:MrBullwinkle
ID: 39272596
With the 2nd way, A doesn't need a reference to C.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39272612
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now