Jump to content


Photo
- - - - -

Java Program


  • Please log in to reply
4 replies to this topic

#1 flareback

flareback

    justified through faith

  • Members
  • PipPipPipPip
  • 1759 posts
  • Gender:Male
  • Location:SC, USA

Posted 26 February 2013 - 07:11 PM

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?


Primary Rig - Intel core i7 920 | Gigabyte EX58 UD4P | 6 GB DDR3 1333 | Sapphire Radeon HD 4850
Secondary Rig - 20 inch iMac | 2.4 Ghz Intel Core 2 Duo | 2 GB DDR2 RAM
Mobile Rig - Asus Eee pc 1000 - 1.6Ghz intel atom | 40Gig SSD | Ubuntu Netbook Remix

#2 SpeedCrazy

SpeedCrazy

    Life is one heck of a ride, so hang on tight!

  • Folding Member
  • 3817 posts
  • Gender:Male
  • Location:Between birth and death.

Posted 26 February 2013 - 07:19 PM

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.


Fold for Team OCC


i7 930 @ 3.9 || Dual-SLI GTX 250 || ASUS P6X58D-E || 3x2GB G.Skill Pi @ 1600 || Corsair TX850w || 2x WD Caviar Black 500gb


#3 flareback

flareback

    justified through faith

  • Members
  • PipPipPipPip
  • 1759 posts
  • Gender:Male
  • Location:SC, USA

Posted 26 February 2013 - 07:36 PM

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.


Primary Rig - Intel core i7 920 | Gigabyte EX58 UD4P | 6 GB DDR3 1333 | Sapphire Radeon HD 4850
Secondary Rig - 20 inch iMac | 2.4 Ghz Intel Core 2 Duo | 2 GB DDR2 RAM
Mobile Rig - Asus Eee pc 1000 - 1.6Ghz intel atom | 40Gig SSD | Ubuntu Netbook Remix

#4 AZNguyen

AZNguyen

    Melting pot of friendship

  • Members
  • PipPipPipPipPipPip
  • 7940 posts
  • Gender:Male
  • Location:FL

Posted 26 February 2013 - 11:37 PM

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.


Gaming || Intel i7 3770K || Gigabyte Z68X-UD3H-B3 || G.Skill 2x 4GB || EVGA GTX 680 2 GB || Corsair TX750 V2 ||

|| 3x Dell UltraSharp U2312HM || Corsair Vengeance K90 || Logitech G700s || Audio-gd NFB 15.32 || Hifiman HE400 ||

HTPC || Intel Celeron G530 || Gigabyte Z68MA-D2H-B3 || G.Skill 4GB || CM Elite 460W ||

NAS || Intel Pentium G630 || Gigabyte Z68MA-D2H-B3 || G.Skill 16GB || Corsair CX430 || IBM M1015 || 21 TB Storage ||


#5 jamesy

jamesy

    New Member

  • Members
  • 12 posts

Posted 26 March 2013 - 06:47 AM

Dude can you reword that in a simpler form ? i do a good but of java think i might have some help here , i might hit you with a question afterwords