Solved

VB.Net Inheritance requiring a reference

Posted on 2013-06-18
7
294 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

696 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