inheritance

  • Thread starter Thread starter netnet
  • Start date Start date
N

netnet

This is an example of the concept I seem to be having a tough time w in C#:

Payment
-amount

Check : Payment
-checkNumber

CreditCard : Payment
-ccNumber
-ccExpiration

Now when I go to use this class structure .....I have to create a container,
populate it, AND all methods have to be implemented on payment at least as
abstracts...which seems like a lot of work.

I dont really need Payment or Check to know anything about ccExpiration for
example.

This is how I have been doing it ...Please let me know if you have cleaner
approach


Payment[] aPayment = new Payment[1];

if(someCondition)
aPayment[0] = new CreditCard(info);
else
aPayment[0] = new Check(info);


Theres a better way right?

Thanks again

Sean
 
netnet said:
This is an example of the concept I seem to be having a tough time w in C#:

Payment
-amount

Check : Payment
-checkNumber

CreditCard : Payment
-ccNumber
-ccExpiration

Now when I go to use this class structure .....I have to create a container,
populate it, AND all methods have to be implemented on payment at least as
abstracts...which seems like a lot of work.

No you don't have to implement all methods in the Payment class. Only
implement amount in Payment. checkNumber in Check and the
ccNumber/ccExpiration in CreditCard.

Why'd you want to implement them all the base class Payment?

Max
 

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