Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.5k points)
A little while ago, I saw a question answered here regarding the fine-grained organization of java packages. For example, my.project.util, my.project.factory, my.project.service, etc.

I can't find it now, so I may as well ask the question.

Are there best practices with regards to the organization of packages in Java and what goes in them?

How do you organize your classes in your Java project?

For instance, a project I'm working on with a few people has a package called beans. It started out being a project containing simple beans, but has ended up (through poor experience and lack of time) containing everything (almost). I've cleaned them up a little, by putting some factory classes in a factory package (classes with static methods that create beans) but we have other classes that do business logic and others that do simple processing (not with business logic) like retrieving a message for a code from a properties file.

Your thoughts and comments are appreciated.

1 Answer

0 votes
by (119k points)

I prefer organizing packages by feature but not by patterns or implementation roles. I think packages like:

  • beans
  • factories
  • collections

are wrong.

I prefer, for example:

  • orders
  • store
  • reports

Hence, I can hide implementation details through package visibility. The factory of orders must be in the orders package so that details about how to create order will be hidden.

If you want to learn Java from the top experts, you can register in this Java Certification program by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Oct 17, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...