Question about inheritance

  • Thread starter Thread starter Versteijn
  • Start date Start date
V

Versteijn

Hello all,

I have the following scheme:

Class Customer
Class Partner Inherits Customer

Now, I have a customer, that wants to be a partner.
A lot of methods and properties of my Customer class do not matter for
the core Partner class. They can be used, but they're not overridden
etc. So I don't want to manually copy all contents of Customer
properties into the Partner object, because then I have to change my
Partner object after every change in these Customer properties.

What would be a right design to do this?

Regards,

Freek Versteijn
 
Do you have a Partner constructor that takes a customer as a paremeter?
If not - why not add one - and use it.
 
* (e-mail address removed) (Versteijn) scripsit:
I have the following scheme:

Class Customer
Class Partner Inherits Customer

Now, I have a customer, that wants to be a partner.
A lot of methods and properties of my Customer class do not matter for
the core Partner class. They can be used, but they're not overridden
etc. So I don't want to manually copy all contents of Customer
properties into the Partner object, because then I have to change my
Partner object after every change in these Customer properties.

Why do you need to copy code if you are inheriting from 'Customer'? You
don't need to override anything if you don't want to do that.
 
Hal Rosser said:
Do you have a Partner constructor that takes a customer as a paremeter?
If not - why not add one - and use it.

Hello Hal,

I have seen those suggestions on the forums, but I can't see how this
would solve my problem.

I would have to set the Customer part of the new Partner object to the
(as parameter to the constructor) given Customer object. How can I do
this? As I mentioned in my first post, I do not want to copy contents
from all Customer properties into Partner, since every
addition/removal of these Customer properties would require a change
in Partner.
Do you see the problem? What can I do?

Thank you in advance!

Regards,

Freek Versteijn.
 
Hello Hal,

I have seen those suggestions on the forums, but I can't see how this
would solve my problem.

I think the point is this. It's a bad idea to think about upgrading a
customer instance to a partner. What you want to do is create a new
Partner object that has some of the same properties as the old Customer.
So you want something that looks like this...

' In Partner.vb
Public Sub New(val as SomePartnerValue, c as Customer)
MyBase(c)
...
End Sub

' In Customer.vb
Public Sub New(c as Customer)
' set the customer properties


The customer is responsible for initiating the customer-specific
properties, and the Partner constructor merely passing the Customer
parameter to the base class.

I'm not entirely sure I like this solution in the general sense, but I'd
have to know a lot more about the project before I could make a
reasonable comment about whether this was the right design.
 
I think the point is this. It's a bad idea to think about upgrading a
customer instance to a partner. What you want to do is create a new
Partner object that has some of the same properties as the old Customer.
So you want something that looks like this...

' In Partner.vb
Public Sub New(val as SomePartnerValue, c as Customer)
MyBase(c)
...
End Sub

' In Customer.vb
Public Sub New(c as Customer)
' set the customer properties

This works fine, exactly what I meant. I wonder though about whether
there are other nice solutions that allow better extensibility.

Let's say I have to extend Partner to some kind of SuperPartner class,
I have to change my Partner class's design. Just like I did now with
Customer. Although this is acceptable, I'd rather have some solution
where this need does not exist and a class can be very easily derived
 

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

Back
Top