Solved

VB.Net Inheritance requiring a reference

Posted on 2013-06-18
7
295 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:Ryan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Ryan
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
Stressed Out?

Watch some penguins on the livecam!

 
LVL 13

Author Comment

by:Ryan
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:Ryan
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 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