How to structure my java packages

Posted by MightyPork on Programmers See other posts from Programmers or by MightyPork
Published on 2014-05-29T14:04:36Z Indexed on 2014/05/29 15:51 UTC
Read the original article Hit count: 193

Filed under:
|
|

I have a Java library, quite a huge one.

I'm asking regarding Best Practices of structuring the source.

For example, the logging sybsystem:

Option 1: All in one package, named to sort nicely

  • Log - static accessor
  • LogMonitor - interface for log minotor
  • LogMonitorBase - abstract class
  • LogMonitorStdout - print log to console
  • LogWriter - interface for file logger
  • LogWriterSimple - log writer with just one log file
  • LogWriterArchiving - log writer that handles old log files

Option 2: Subpackages for Monitors and Writers, with better names

  • Log
  • monitors/LogMonitor
  • monitors/BaseMonitor
  • monitors/StdoutMonitor
  • writers/LogWriter
  • writers/SimpleLog
  • writers/ArchivingLog

The second maybe looks better, but perhaps it's not so practical from the java point of view (two extra packages).

What do you suggest as the best practice here? A lot in one package, grouped by naming prefixes, or a lot of subpackages with better names?

© Programmers or respective owner

Related posts about java

Related posts about packages