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


i'm bulding application in java play 2. modelling different classes of people, each different relationships other classes related application process. each application has signatory, certificateholder, , enrolmentofficer.

i realised since 1 person or of things, redundant store information on them 3 times. refactoring in order!

i decided have single person class store 1 of each of signatory, certificateholder, , enrolmentofficer classes via object composition. access of properties using person.signatory. notation.

what i'm wondering this: since 3 specialised classes not exist outside of person, better achieve goal using inner classes? mean 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 seem remove need store seprate entity in database each signatory, certificateholder, , enrolmentofficer, i'm not sure if ebean can translate design database schema.

which method better suits purpose?

edit: inner class method not work; it's incompatible way ebean handles relationships. i'm going ask moderator delete topic.

you could/should use inheritance since each of signatory, certificateholder, , enrolmentofficer is-a person , fields of person common in oll classes derived it. classes should be:

class signatory extends person{ ... }   class certifiedholder extends person{ ... }   class enlormentofficer extends person{ ... } 

if use hibernate/jpa can apply inheritance on entities , consequently on database tables: have entity inheritance.

regarding comment, can have class derive 1 subclasses , hence "combine" 2 functionalities.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -