473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Question about inheritance

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
5 879
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
* 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
"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
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gert Van den Eynde | last post by:
Hi all, I have a question on interface design: I have a set of objects that are interlinked in the real world: object of class A needs for example for the operator() an object of class B. On...
2
by: Tony Johansson | last post by:
Hello Experts!! Here we use multiple inheritance from two classes.We have a class named Person at the very top and below this class we have a Student class and an Employee class at the same...
8
by: __PPS__ | last post by:
Hello everybody, today I had another quiz question "if class X is privately derived from base class Y what is the scope of the public, protected, private members of Y will be in class X" By...
6
by: Peter Oliphant | last post by:
I just discovered that the ImageList class can't be inherited. Why? What could go wrong? I can invision a case where someone would like to add, say, an ID field to an ImageList, possible so that...
7
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears...
23
by: neoedmund | last post by:
There's a program, it's result is "unexpected aaa", i want it to be "expected aaa". how to make it work? class C1(object): def v(self, o): return "expected "+o class C2(object):
6
by: RSH | last post by:
I am still trying to grasp the use of real world Objects and how to conceptualize them using a business scenerio. What I have below is an outline that I am wrestling with trying to figure out a...
3
by: RSH | last post by:
I have a simple question regarding inheritance in a web form. I have a DropDownList in an aspx form. It is called DropDownList1 I have a class that will be overriding the render event so I...
8
by: RSH | last post by:
Hi, I am working on some general OOP constructs and I was wondering if I could get some guidance. I have an instance where I have a Base Abstract Class, and 4 Derived classes. I now need to...
4
by: sip.address | last post by:
Hi there, When creating interfaces and implementations, the usual thing is doing somethign like class Interface { public: virtual void f() = 0; virtual void g() = 0; };
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.