I'm writing Java project and I want to have in my system 3 types of account - Guest, Investor, Beneficiary. Each of them have the same fields (like email, password, name, last name, phone number etc) but some fields are unique for specified account - for example company information like company name, company address etc is only for Investor. What is best way to create model for that in Java? I had one class Account with all fields and all users were stored on the same table in database. I thought this is not good idea because I had a lot of null value, for example Guest was stored with null information about company etc. So I splited code for 4 class.
- Account have all commons fields - parent class.
- Guest extends Account and I added only 1 extra field.
- Investor extends Account and I added a lot of fields about company etc.
- Beneficiary extends Account and I added some new fields like address etc.
Looks better but I have a lot of similar codes (controllers for receive data from front-end, persistence layer and so on). I think is a little bit too complicated.
What is the best way to solve this problem? Wich proposal is better ? Do you have any better solution?
Please help. Regards, Lukas!
Aucun commentaire:
Enregistrer un commentaire