Jump to content

Java Program


flareback

Recommended Posts

So I'm working on a program and I'm not sure how I want to have it designed.

 

I have two classes a Person class and a Business class. I want to track those are donating to a cause. So a person can be a donor, but they may not be. And a Business can be a donor but they may not be. It would make sense for donor to extend Person and Business but you can't extend multiple classes.

 

So should I have Person and Business extend donor? But not all people are donors and I usually think of classes that extend as being an "is-a" relationship (Animal class and a Dog class that extends Animal, a Dog is an Animal but not all animals are dogs). So to me this doesn't seem to be ideal.

 

Any thoughts?

Share this post


Link to post
Share on other sites

I don't have a clue about java but it seems to me you could do it this way:

Have a "entity" class(person and business) and as an extension of that have business, person, business-donor and person-donor. or just business and person and person and then extend those further. Not ideal but it could maybe work... as i say i am clueless on java.

Hope that sparks an idea.

Share this post


Link to post
Share on other sites

I don't have a clue about java but it seems to me you could do it this way:

Have a "entity" class(person and business) and as an extension of that have business, person, business-donor and person-donor. or just business and person and person and then extend those further. Not ideal but it could maybe work... as i say i am clueless on java.

Hope that sparks an idea.

 

I thought about having a business-donor and a person-donor class but the donor parts are going to be very similar. Seems like I would be re-writing a lot of code. Plus if I changed anything I'd have to change it in both places.

Share this post


Link to post
Share on other sites

It's been awhile since I did Java, but I think....

 

Have both People and Business extends Donor. Then use a flag variable to state whether or not they are a donor. Then just do whatever it is you need to do that is shared within the Donor class. Then everything that's different in People and Business.

Share this post


Link to post
Share on other sites

  • 4 weeks later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...