Naming a phased VS package individually?

I know that this has some related posts, but I have some specific questions that I hope I can get help with. Sorry if they are very simple.

Here is an example problem - very simplified, but you get an image - I have several objects that have some common function, for example. departments of the pharmaceutical company - neurology, oncology, infection, etc. All of them must analyze patient document files and upload data to the database. Of course, the nature of the data is slightly different for each department. If I used the feature package, I would have

com.company.neurology Neurology.java NeurologyDocument.java NeurologyDAO.java com.company.infection Infection.java InfectionDocument.java InfectionDAO.java 

etc .. The problem is that I need an abstract class that Document classes should extend, for example.

 AbstractDocument.java public class AbstractDocument { public void validateDocument(){...} public void readDocumentHeader(){...} public void readDocumentFooter(){...} ... } 

Some data access files, for example

 DBConnection.java public class DBConnection { public void makeConnectionToDB() {... } public void createCache() {... } public void closeConnectionToDB() {... } } 

some error classes

 ParseError.java, PatientNotFoundException etc. 

If packages are by function, where do these common classes / interfaces go?

+6
source share
2 answers

I do not think that in your case you should create a common package. I assume that something is wrong with the abstractions used.

You should find a way to combine classes for the same purpose in some package and put this package under com.company.shared.<feature_name> .

In your case, it could be:

  • com.company.shared.database
  • com.company.shared.data_parsing

No problem if the package contains only one or two classes. But he should combine only classes with the same goal and have a clear name.

Avoid names for packages and classes like common . The name should speak for itself.

+1
source

I would recommend keeping things simple. If you are not lazy about this, posting them to com.company is a smart solution.

The danger here is that this requires the discipline to move them into separate packages when you notice groups of organizational commonality.

In the case of your example, you have already started making these connections - your entry is itself segmented to offer these additional packages:

 com.company.dataaccess com.company.error 

AbstractDocument.java probably does not deserve this own package. If you create more related interfaces / classes and then move them to the appropriate package, but don't forget about the problems, worrying about it until it becomes a problem.

0
source

Source: https://habr.com/ru/post/986682/


All Articles