Joe,
As Herfried suggests, I would recommend a factory method/pattern.
Something like:
' don't allow this class to be instantiated directly
Public MustInherit Class Base
' don't allow this class to be instantiated directly
Protected Sub New
End Sub
Public Shared Function Create() As Base
' read config file
Select Case configSetting
Case A
Return New DerivedA
Case B
Return New DerivedB
Case ...
End Select
End Function
End Class
Public Class DerivedA
Inherits Base
Friend Sub New()
End Sub
End Class
Public Class DerivedB
Inherits Base
Friend Sub New()
End Sub
End Class
Then to use it you use:
Dim lInstance As Base = Base.Create()
Instead of a Select Case I have used Type.GetType coupled with
Activator.CreateInstance to create an instance of the derived class...
NOTE: The "Shared" in "Public Shared Function Create" allows the Create
function to be called without creating an instance of the Base class first.
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
"Joe HM" <un*******@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
| Hello -
|
| I have a Base Class where I want a New() implemented that can be called
| from the outside. This New() should create an instance of the
| appropriate cDerivedX Class ...
|
| The following shows a scenario where it was determined that cDerivedA
| is needed based on a configuration file.
|
| Dim lInstance As New cBase()
|
| This statement should then create an instance of ...
|
| Class cDerivedA
| Inherits cBase
| ...
| End Class
|
| During a different run the configuration file requires cDerivedB being
| used ...
|
| Dim lInstance As New cBase()
|
| This statement should now create an instance of ...
|
| Class cDerivedB
| Inherits cBase
| ...
| End Class
|
| So I was trying to tweak the Public Sub New() in cBase. How can I call
| the New() of the appropriate cDerivedX Class and create an instance of
| it that will be accessed through lInstance?
|
| Thanks a lot!
| Joe
|