J
Jason
I have a fun OOP question.
I want to have a base class that contains methods that should always be
overridden... I can't mark the base class methods as MustOverride because
they will "overridden" by Shared (static) methods, so I have to code a "work
around".
In the code below, I've identified where I am getting an error. Somehow I
need to execute the Derived Class's ChangePassword method instead of the
base class's ChangePassword method.
I've confirmed that Me.GetType().ToString() resolves to MyDerivedClass1 or
MyDerivedClass2, so there HAS to be a way to do this... I just need a few
suggestions.
Thanks in advance,
-- Jason
Here's the class definitions:
Public MustInherit Class BaseClass1
Overridable Sub ChangePassword( _
ByVal Username as String, _
ByVal Password as String, _
ByVal theOU as String, _
ByVal theEmployeeEmailAddr as String)
'next line won't compile...
CType(Me, Me.GetType()).ChangePassword(Username, Password, theOU,
theEmployeeEmailAddr)
End Sub
End Class
Public Class MyDerivedClass1
Public Shared Sub ChangePassword( _
ByVal username as String, _
ByVal password as String, _
ByVal theOU as String, _
ByVal theEmployeeEmailAddr as String)
' code goes here where I actually change the users password using
ADSI or System.DirectoryServices
End Sub
End Class
Public Class MyDerivedClass2
Public Shared Sub ChangePassword( _
ByVal username as String, _
ByVal password as String, _
ByVal theOU as String, _
ByVal theEmployeeEmailAddr as String)
' code goes here where I would pass the request off to a web service
to handle the request instead of doing it here...
End Sub
End Class
Public Class MyMainClass
Public Sub ChangePassword( _
ByVal username as string, _
ByVal Password as String, _
ByVal theOU as String, _
ByVal theEmployeeEMailAddr as String)
Dim theBaseClass as BaseClass1
Select case theOU
case "FirstOrginizationalUnit"
theBaseClass = New DerivedClass1
case "SecondOrginizationalUnit"
theBaseClass = New DerivedClass2
End Select
theBaseClass.ChangePassword(username, password, theou,
theemployeeemailaddr)
End Sub
End Class
I want to have a base class that contains methods that should always be
overridden... I can't mark the base class methods as MustOverride because
they will "overridden" by Shared (static) methods, so I have to code a "work
around".
In the code below, I've identified where I am getting an error. Somehow I
need to execute the Derived Class's ChangePassword method instead of the
base class's ChangePassword method.
I've confirmed that Me.GetType().ToString() resolves to MyDerivedClass1 or
MyDerivedClass2, so there HAS to be a way to do this... I just need a few
suggestions.
Thanks in advance,
-- Jason
Here's the class definitions:
Public MustInherit Class BaseClass1
Overridable Sub ChangePassword( _
ByVal Username as String, _
ByVal Password as String, _
ByVal theOU as String, _
ByVal theEmployeeEmailAddr as String)
'next line won't compile...
CType(Me, Me.GetType()).ChangePassword(Username, Password, theOU,
theEmployeeEmailAddr)
End Sub
End Class
Public Class MyDerivedClass1
Public Shared Sub ChangePassword( _
ByVal username as String, _
ByVal password as String, _
ByVal theOU as String, _
ByVal theEmployeeEmailAddr as String)
' code goes here where I actually change the users password using
ADSI or System.DirectoryServices
End Sub
End Class
Public Class MyDerivedClass2
Public Shared Sub ChangePassword( _
ByVal username as String, _
ByVal password as String, _
ByVal theOU as String, _
ByVal theEmployeeEmailAddr as String)
' code goes here where I would pass the request off to a web service
to handle the request instead of doing it here...
End Sub
End Class
Public Class MyMainClass
Public Sub ChangePassword( _
ByVal username as string, _
ByVal Password as String, _
ByVal theOU as String, _
ByVal theEmployeeEMailAddr as String)
Dim theBaseClass as BaseClass1
Select case theOU
case "FirstOrginizationalUnit"
theBaseClass = New DerivedClass1
case "SecondOrginizationalUnit"
theBaseClass = New DerivedClass2
End Select
theBaseClass.ChangePassword(username, password, theou,
theemployeeemailaddr)
End Sub
End Class