Wednesday, 7 August 2013

Would inner classes work better for what I'm modelling?

Would inner classes work better for what I'm modelling?

I'm bulding an application in Java with Play 2. I was modelling different
classes of people, each with different relationships to some other classes
related to an application process. Each Application has a Signatory, a
CertificateHolder, and an EnrolmentOfficer.
I realised that since one person could be any or all of those things, it
was redundant to store the information on them three times. So some
refactoring was in order!
I decided to have a single Person class that would store one of each of
the Signatory, CertificateHolder, and EnrolmentOfficer classes via object
composition. I could then access any of their properties using
person.signatory. notation.
What I'm wondering is this: since the three specialised classes do not
exist outside of a Person, would I better achieve my goal using inner
classes? I mean like so:
public class Person {
public class Signatory {
// Signatory fields go here
}
public class CertificateHolder {
// CertificateHolder fields go here
}
public class EnrolmentOfficer {
// EnrolmentOfficer fields go here
}
// More general Person code goes here
}
It would seem to remove my need to store a seprate entity in the database
for each Signatory, CertificateHolder, and EnrolmentOfficer, but I'm not
sure if ebean can properly translate this design into a database schema.
Which method better suits my purpose?

No comments:

Post a Comment