Ryan
asked on
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.
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.
ASKER
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.
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.
When you add a reference to B, you also need to add reference to C because it is used by B.
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
With the 2nd way, A doesn't need a reference to C.
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.
what do u mean by that?
is it override function in B?
can u give concrete example?