L
Larry Lard
[formerly posted to ms.public.dotnet.vb.general, but this seems to be a
much higher traffic group]
Hi,
This seems to me like a problem that has a simple solution but I can't
for the life of me work it out.
Suppose I have a base class Employee
Public Class Employee
Public FullName As String
....
End Class
and from it I define the derived subclass Supervisor
Public Class Supervisor
Inherits Employee
Public MaxTeamMembers As Integer
....
End Class
Suppose now I have an employee
Dim e As Employee
who has been made a supervisor. I want to create a Supervisor object s
with all the Employee properties copied from e. I thought of making a
constructor like this in Supervisor:
Public Sub New(fromEmployee As Employee)
MyBase().New
Me.FullName = fromEmployee.FullName
End Sub
but that would break if Employee was ever changed to have more
properties (also in my real app the base class has LOTS of properties).
I thought I might be able to do something like
Public Sub New(fromEmployee As Employee)
MyBase().New
MyBase = fromEmployee ' oh no you can't
End Sub
but I can't. The very first thing I tried was just casting an As
Employee variable to Supervisor, but it wouldn't let me - after some
thought I now understand that it is correct.
What is the proper way to do what I want?
Thanks,
much higher traffic group]
Hi,
This seems to me like a problem that has a simple solution but I can't
for the life of me work it out.
Suppose I have a base class Employee
Public Class Employee
Public FullName As String
....
End Class
and from it I define the derived subclass Supervisor
Public Class Supervisor
Inherits Employee
Public MaxTeamMembers As Integer
....
End Class
Suppose now I have an employee
Dim e As Employee
who has been made a supervisor. I want to create a Supervisor object s
with all the Employee properties copied from e. I thought of making a
constructor like this in Supervisor:
Public Sub New(fromEmployee As Employee)
MyBase().New
Me.FullName = fromEmployee.FullName
End Sub
but that would break if Employee was ever changed to have more
properties (also in my real app the base class has LOTS of properties).
I thought I might be able to do something like
Public Sub New(fromEmployee As Employee)
MyBase().New
MyBase = fromEmployee ' oh no you can't
End Sub
but I can't. The very first thing I tried was just casting an As
Employee variable to Supervisor, but it wouldn't let me - after some
thought I now understand that it is correct.
What is the proper way to do what I want?
Thanks,