Best Java Package Design

I am currently trying to figure out how to develop a small application. An application is a service in which there are some files as input (excel files or pdf files representing reports from third-party companies), and its output should consist in creating an invoice from various reports. These invoices are then sent by hand to the issuing company. I know how to make an application do what I want, but currently all classes are in the same package, the default package. I would like to change that. So I started to rename classes so that they all fit into the metaphor: "office." These are my current classes and interfaces:

  • OfficeDesk (hub like everything)
  • Translator (opens pdf and excel files, parses them into String)
  • Report (an object representing the contents of a pdf or Excel report file)
  • ReportBook (list of all reports)
  • BookKeeper (converts the Rows report to reports, adds reports to ReportBook, implements ReadSkill)
  • ReadSkill (interface, makes BookKeeper convert the string to a report object)

  • TypeSetter (some common String utilities)

  • Typist (converts ReportBook to pdf, uses TypeSetter, implements InvoiceTypingSkill)
  • InvoiceTypingSkill (forces Typist to implement methods such as TypeReportTable (), TypeDueDate (), etc.).
  • JobAgency (a service that briefly looks at a PDF file to decide which source (reporting company) the pdf file is from, and then provides a specialized BookKeeper (a subclass of the BookKeeper class, fe WeylandCorporationBookKeeper for an accountant who knows how to read reports from Weyland Corporation) or Typist for job)

With this, I have many classes that need to use ReportBook and Report, which I planned to put in the "filingcabinet" package. So now BookKeeper imports filingcabinet. Typical too, etc .... How can I pack this so that the packages are not needed by each other? Or is it really good practice that they use each other? FE

  • BookKeeper.writeRecordToBook (ReportRecord Record, BookBook Book)

against

  1. BookKeeper.writeRecordToBook (String [Object] Record, Vector Book)

I think (1.) is more readable, but makes BookKeeper have a dependency. On the other hand, there is no dependency on (2.), just common java types, but less readable. What is better here? Also, what would you name packages (or should there be only one, with so few classes)

My current packages

  • office (classes: OfficeDesk)
  • filingcabinet (classes: ReportBook, Report)
  • services (classes: JobAgency, Translator, TypeSetter)
  • services.bookkeeping (classes: BookKeeper, ReadingSkill, all subclasses of BookKeeper)
  • services.typist (classes: Typist, InvoiceTypingSkill, all subclasses of Typist)

I understand that this could have been written with a more concise example, but thanks for reading and for any input / opinion!

+7
java design packages
source share

No one has answered this question yet.

See related questions:

6170
Is Java pass-by-reference or pass-by-value?
3799
How do I read / convert an InputStream to a string in Java?
3324
How to generate random integers in a specific range in Java?
3073
How to efficiently iterate over each entry on a Java map?
3044
Creating a memory leak using Java
2956
What is the difference between public, secure, batch, and private in Java?
2936
When to use LinkedList over ArrayList in Java?
2853
How to convert String to int in Java?
2248
Is the finally block always executable in Java?
2171
How to determine if an array contains a specific value in Java?

All Articles