• Post Reply Bookmark Topic Watch Topic
  • New Topic

which package should I store these POJOs under if some of these POJOs are shared by multiple modules  RSS feed

 
Monica Shiralkar
Ranch Hand
Posts: 922
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a package structure such as com.module1.model.MyPojo

examples:

com.module1.MyPojo1.java
com.module1.MyPojo2.java
com.module2.MyPojo3.java
com.module3.MyPojo2.java

Now the classes com.module1.MyPojo2.java and com.module2.MyPojo2.java are the same POJOs but in different modules. There is redundancy here as these are stored twice in two modules. How should I store these in a proper way?


thanks.
 
Monica Shiralkar
Ranch Hand
Posts: 922
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry. It got reposted as there seems to be some issue with EDIT button. It is not visible on my thread today.
 
M Khalid
Ranch Hand
Posts: 57
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not completely sure, but one of the approach can be - if all the .java files are same and are in different modules, then you can make a generic/general package say "com.module.pojo" and store all the distinct java file in that, after that you can import this package every where needed.
Hope that was a correct understanding of you problem.
 
Monica Shiralkar
Ranch Hand
Posts: 922
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not completely sure, but one of the approach can be - if all the .java files are same and are in different modules, then you can make a generic/general package say "com.module.pojo" and store all the distinct java file in that, after that you can import this package every where needed.


Thanks. But these POJOs belong to different modules of the project.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So? Are these "modules" compiled separately or all part of the same project?
 
Monica Shiralkar
Ranch Hand
Posts: 922
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So? Are these "modules" compiled separately or all part of the same project?


These are part of same Core Java Project.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then why can't you have a package (thinking of them as "modules" is odd) that contains classes used by the other packages? That's what packages are all about.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear +1

Usually I would have something like com.myproject.data which contains all POJOs. This can also contain, in turn, maybe enums, constants used by the POJOs (e.g. A User object might have an enum Role)
Not only this makes for good structuring, but if required, you can export this package as a jar, drop the jar in another project's classpath and you are ready to go.(e.g A distributed system where you exchange serialized data via say JSON)
 
Monica Shiralkar
Ranch Hand
Posts: 922
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks. I corrected accordingly.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!