0

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?

MightyPork
  • 129
  • 1
  • 8
  • 1
    recommended reading: **[Why is asking a question on “best practice” a bad thing?](http://meta.stackexchange.com/a/142354/165773)** – gnat May 29 '14 at 14:09
  • then what do you suggest? I've seen the java api packages are super messy, all in one package. Is that the way to go? – MightyPork May 29 '14 at 14:11
  • Things that are almost always used together should be together. – Doval May 29 '14 at 14:12
  • questions about "the way to go" have been asked and answered before, see [How to divide OO project into packages?](http://programmers.stackexchange.com/q/238606/31260) "In terms of guidelines you could start with SOLID and Packaging Principles..." and [What are the steps to grouping related classes into packages](http://programmers.stackexchange.com/q/216765/31260) "developers are expected to package at their discretion, following the general guidance and ideas provided by conventions... The goal is to make reading and understanding the code easier..." – gnat May 29 '14 at 14:18

0 Answers0