mardi 2 octobre 2018

One universal class or 3 specified class for specific type of account in system

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.

  1. Account have all commons fields - parent class.
  2. Guest extends Account and I added only 1 extra field.
  3. Investor extends Account and I added a lot of fields about company etc.
  4. 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