By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

Question about inheritance

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Do you have a Partner constructor that takes a customer as a paremeter?
If not - why not add one - and use it.

"Versteijn" <ve*******@538mail.nl> wrote in message
news:4d**************************@posting.google.c om...
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

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Nov 21 '05 #2

P: n/a
* ve*******@538mail.nl (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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

P: n/a
"Hal Rosser" <hm******@bellsouth.net> wrote in message news:<DP******************@bignews4.bellsouth.net> ...
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.
Nov 21 '05 #4

P: n/a
On 2004-08-27, Versteijn <ve*******@538mail.nl> wrote:
"Hal Rosser" <hm******@bellsouth.net> wrote in message news:<DP******************@bignews4.bellsouth.net> ...
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 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 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.

Nov 21 '05 #5

P: n/a
> 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
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.