Sam,
In addition to the other comments.
I would consider making the Customer object contain a reference to the
Person object, then delegate all the "Person" properties to the underlying
Person object.
Alternatively rather then having Customer inherit from Person, I would
consider using the Role Pattern and make Customer a Role that Person can
have. This allows Person to change its Role (to Customer) without needed to
copy the Person attributes.
' quick sample of the Role Pattern:
Public MustInherit Class PersonRole
Private Class NullRole
Inherits PersonRole
' default behavior & attributes for a Person without a specific
role.
End Class
Public Shared ReadOnly Null As PersonRole = New NullRole
' behavior & attributes common to roles
End Class
Public Class Person
Private m_role As PersonRole
Public Sub New()
m_role = PersonRole.Null
End Sub
Public Property Role() As PersonRole
Get
Return m_role
End Get
Set(ByVal value As PersonRole)
If value Is Nothing Then Throw New
ArgumentNullException("Role")
m_role = value
End Set
End Property
' behavior & attributes specific to a Person
End Class
Public Class CustomerRole
Inherits PersonRole
' behavior & attributes specific to a Customer
End Class
Person.Role could be a collection if a Person supported multiple
simultaneous roles.
Hope this helps
Jay
"Sam Kuehn" <sa******@hotmail.com> wrote in message
news:09****************************@phx.gbl...
What is the correct way to "widen" the interface of an
object? Let me explain (this is not a real example but
should illustrate my point). Say you have a person
object with some properties. And you also have a
customer object that inherits from the person object and
adds some properties. I know that you cannot directly
cast from a person to a customer. But, I am in a
situation where I need to do exactly that. I could go
and copy all of the properties of the person object into
the customer object but that doesn't seem like a very
good solution. Any ideas?