how to design model classes in java project -


i new jsp. want test project familiar it.

the project have selected design website people can register on , make resume themselves.

each person registered can define projects has worked on before.

for example, if register user name sht , define projecta , projectb, means these projects should displayed in resume.

by way, want use mvc design.

my problem when want design model classes, don't know approach best following scenarios:

1- first thing came mind that, can have class users contains userid , username , ...
need class projects contains projectname , projectid, , again class userproject has userid, projectid able find project belongs specific user.

in example have user object user class userid 1 , username 'sht'.

i have 2 objects project class :

object1{projectid = 1, projectname = "projecta"}

object2{projectid = 2, projectname = "projectb"}

and again have these objects userproject :

object1{userid = 1, projectid = 1} ,

object2 {userid =1, projectid = 2}

2- second way, can have class projects has these fields : projectid, projectname. have again class users these fields: userid, username , list of user's projects.

forexample in way have :

2 objects projects :

object1{ projectid = 1 , projectname = "projecta"}

objectb { projectid = 2, projectname = "proojectb"}

and object user :

user1 { userid = 1 , username = "sht", listofprojects = {projectid = 1,projectid = 2}}

these 2 ways came mind. don't know 1 better in situation. think maybe first way better, because later might want add feature every user can register projects , each user can have list of skills , on. these features think maybe first way easier handle.

can please me find out 1 better?

if think there better way, appreciate it.

thanks in advance attention.

i'd there 3 points want judge solution on.

  • storage space
  • search time project -> users
  • search time user -> projects

for 2 solutions storage space asymptotically equal, every userproject object in solution 1 there 1 item in listofprojects of user in solution 2.

for doing project -> users search behave equally since in solution 2 you'd have go through every user , see projects worked on same going through every userproject in solution 1.

for doing user -> projects search solution 2 alot faster since can directly list user has answer.

i'm gonna propose 2 other solutions myself too, lets call them solution 3 , solution 4.

solution 3: same solution 2 other way around, projects store list of users working on them.

solution 4: solution 2 , solution 3 combined, users store on projects working , projects store users working on them.

pros , cons of solutions:

  • solution 1
    • small storage
    • slow project -> users search
    • slow user -> projects search
  • solution 2
    • small storage
    • slow project -> users search
    • fast user -> projects search
  • solution 3
    • small storage
    • fast project -> users search
    • slow users -> project search
  • solution 4
    • big storage
    • fast project -> users search
    • fast user -> projects search

i'd solution 1 definitly worst option available, others depend on situation.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -