I have two types of java beans that can be associated with a User java bean:
PrivateTeacher
and CompanyTeacher
.
These two java beans are similar, only for one of their properties, say "subject", the PrivateTeacher
will always have one while the CompanyTeacher
can have several.
Would it make more sense to have a single java bean for both of these types of users where the "subject" field will be an ArrayList and the PrivateTeacher will only fill one element of the ArrayList whereas the CompanyTeacher can fill several?
Or should I have two separate java beans: one with an int field and another with an ArrayList<Integer>
field (for the subject id's field)?
On one hand, the latter way is more precise. On the other, I don't want to limit methods that I have such as say, "findTeachers", which could satisfy both types of java beans (pass a parameter saying the bean type: "company" or "private" and then the User bean will be different but the Teacher bean will be the same). Any suggestions or explanations? Thank you
It depends...
If you want to treat both
PrivateTeacher
andCompanyTeacher
in the same manner (polymorphicaly) thenList<Integer>
(notArrayList
) would be a better approach. But if this is not the case then - use the more precise way to describe them.