There are three parts to my code A, B, C. B is a class library which references A which is also a class library. In A, a class MathOperations
is defined which contains a function ADD
. The part B has a class Factory
which in-turn has a function createMathsObject
which returns an object of MathOperations
type. The part C refers to B. I can do away with part B and create the object of MathOperations
type in part C and make C reference A directly where that class is defined. However I am trying to see how I can de-couple sections of the code, in this case A and C.I give the code for each of the three parts A, B and C. The error message that I get is mentioned later for which I need your help.
Part A: Class Library - Named as MathLibrary.dll
Public Class MathOperations
Function ADD(ByVal a As Integer, ByVal b As Integer) As Integer
Return (a + b)
End Function
End Class
Part B: Class Library - Named as FactoryMathsLibrary.dll which references MathLibrary.dll
Imports MathLibrary
Public Class Factory
Shared Function createMathsObject() As MathOperations
Return New MathOperations()
End Function
End Class
Part C: Exe file - which references FactoryMathsLibrary.dll
Imports FactoryMathsLibrary
Module Module1
Sub Main()
Dim a, b As Integer
Dim m As Object = Factory.createMathsObject() 'Error comes here
Console.Write("Enter 1st value: ")
a = Console.ReadLine()
Console.Write("Enter 2nd value: ")
b = Console.ReadLine()
Console.WriteLine("a + b = {0}", m.ADD(a, b))
Console.ReadLine()
End Sub
End Module
I was under the impression that since C references B and B references A, everything would be fine. But I am getting an error in the line Dim m As Object = Factory.createMathsObject()
. The error message is as follows: Can someone pls help with the reason behind the error and the solution??