Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8804235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:33:03+00:00 2026-06-14T01:33:03+00:00

Consider the following example. There is a server application that has three layers. The

  • 0

Consider the following example.

There is a server application that has three layers. The service layer that is exposed to the clients, the database layer that is used for persistence and the business layer that calculates something.

The application serves three different types of data. Users, Payments and Worktimes.

How should I package my application?
Package by layer:

foo.bar.service
  UserService.class
  PaymentsService.class
  WorktimeService.class
foo.bar.persistence
  UserPersistenceService.class
  PaymentPersistenceService.class
  WorktimePersistenceService.class
foo.bar.business
  PaymentCalculator.class

Or package by type:

foo.bar.user
  UserService.class
  UserPersistenceService.class
foo.bar.payment
  PaymentService.class
  PaymentsPersistenceService.class
  PaymentCalculator.class
foo.bar.worktime
  WorktimeService.class
  WorktimePersistenceService.class

I guess the first example could become confusing if the application grows and more and more logic is implemented. However, it appears to be easier to find the right place when the task is to “extend the persistent service layer to do something fancy”.
The second example can be easier extended without flooding packages with millions of classes.

Is there any best practice to choose between them? Or do you guys have any other idea of a package structure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:33:04+00:00Added an answer on June 14, 2026 at 1:33 am

    As far as I am concerned I would package by layer AND type :

    • foo.bar.service.user.UserService
    • foo.bar.persistence.user.UserPersistence
    • And so on

    For most of my projects I use maven and some multi modules :

    1. Domain Model (Model Objects)
    2. Persistence
    3. Service
    4. Applications

    With this way, you could get different jars (or not if you have got only a simple project) and it is easier to retrieve the good place to extend/modify the existing sources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider following example: The source image consists of 6 areas that need to
Are there really any significant advantages to overload methods? Let's consider the following example:
Consider the following example. When I write is-a, I mean a column that is
Let's consider the following example. I have a parent process that creates a pipe,
Consider the following example program: next :: Int -> Int next i | 0
Consider the following example. I have an interface MyInterface, and then two abstract classes
Consider the following example: int size = 10, *kk = new int[size]; for (int
Consider the following example: struct Scanner { template <typename T> T get(); }; template
Consider the following example $q = Doctrine::getTable('User')->createQuery('u') ->where('u.username = ?', 'test'); If another related
Consider the following example: ( live demo here ) HTML: <div class=board> <div class=row>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.