Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Is it a bad practice to have a package with only one class in it?</p> </blockquote> <p>Not necessarily. It could be a sign of somebody getting obsessed with classifying things. On the other hand, it could just be a logical consequence of a sensible general classification scheme applied in an unusual case. </p> <p>An example of the latter might be where you have a general API, and multiple implementations of that API, where each of the implementations consists of multiple classes. But one of those implementations (lets call it the Null implementation) consists of just one class.</p> <p>The real test is whether the package structure is serving its purpose(s):</p> <ul> <li><p>Is it making it easier to find library classes?</p></li> <li><p>Do the packages organize the application classes along the lines of the application's logical module structure?</p></li> <li><p>Does the structure allow you to effectively make use of "package private" visibility?</p></li> </ul> <blockquote> <p>Would it make more sense just to move the single class to a util package that would contain other random useful classes?</p> </blockquote> <p>Not necessarily. If the class is just another "randomly useful" leaf class, then there is a good case for moving it. On the other hand, if it has a specific function and is not intended to be used generally, then it may be better to leave it where it is.</p> <p>It is best not to get too obsessed with creating elegant package hierarchies, or with rejigging them when they turn out to be not as elegant (or useful) as you first thought. There are usually more important things to do, like implementing functionality, writing tests, writing documentation and so on.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload