Class factory reflection question

N

Nancy

I have the following situation and could use some advise.
I have a Base Class CreditReport, classes BoatCreditReport and
HomeCreditReport Inherit from CreditReport.
I would like to have the CreditReport class in a separate project from
BoatCreditReport and HomecreditReport for departmental code
development reasons.

I have a CreditFactory class which uses reflection to instantiate the
approprite subclass( BoatCreditReport, HomeCreditReport, etc) based on
some parm passed in.
The parm passed in will be a fully qualified class name pulled from
the web.config. No problem there.

The problem is; Project 2 & 3 need to reference Project 1 ( because
they inherit). Correct? The CreditFactory(project 1) will create an
instance of either BoatCreditReport or HomeCreditReport.
How can it do this without a reference? I certainly don't want to
reference Project 1 from project 2 ( although I tried that and the
reflection did not work). See code below

Any advise here would be greatly appreciated.



PROJECT 1

Public MustInherit Class CreditReport
Public objCredit As New Credit()

Public Function RequestReport(ByVal str As string) As Double

Blah,blah, blah


Return somedouble

End Function

Public Function GetReportSummary(ByVal str1 As string) As
Credit
Blah,blah, blah

Return somecredit
End Function

Public MustOverride Sub ChoicePointParser(ByVal str3 As
String)
Public MustOverride Function ValidateCreditRequest(ByVal str4
As string) As String

End Class


Public Class CreditFactory

Private Sub New()

End Sub

Public Shared Function Create(ByVal reportType As String) As
CreditReport
Dim credreport As CreditReport
credreport = Nothing
Dim typ As System.Type = System.Type.GetType(reportType)
credreport = CType(Activator.CreateInstance(typ),
CreditReport)
Return credreport
End Function

End Class


PROJECT 2

Public Class BoatCreditReport
Inherits CreditReport

Public Overrides Sub ChoicePointParser(ByVal str3 As String)
'parsing code specific to boat credit report
End Sub

Public Overrides Function ValidateCreditRequest(ByVal str4 As
string) As String
'validation code specific to boat credit report

End Function

End Class


PROJECT 3

Public Class HomeCreditReport
Inherits CreditReport

Public Overrides Sub ChoicePointParser(ByVal str3 As String)
'parsing code specific to Home credit report
End Sub

Public Overrides Function ValidateCreditRequest(ByVal str4 As
string) As String
'validation code specific to Home credit report

End Function

End Class
 
M

Mattias Sjögren

I have a CreditFactory class which uses reflection to instantiate the
approprite subclass( BoatCreditReport, HomeCreditReport, etc) based on
some parm passed in.
The parm passed in will be a fully qualified class name pulled from
the web.config. No problem there.

If you include the assembly name after the class name (in the format
"Namespace.Class, AssemblyName"), then Type.GetType() will load the
assembly, so you don't need a compile time reference to it.



Mattias
 
N

Nancy

Mattias Sjögren said:
If you include the assembly name after the class name (in the format
"Namespace.Class, AssemblyName"), then Type.GetType() will load the
assembly, so you don't need a compile time reference to it.



Mattias

Thanks that worked out great
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top