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

  • Home
  • SEARCH
  • 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 7183473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:59:14+00:00 2026-05-28T17:59:14+00:00

This is a problem we encounter often. There must be some best practices to

  • 0

This is a problem we encounter often. There must be some best practices to address this…

Simplified Question

Where’s the best place to put common code that manipulates POJOs?

such that:

  • POJOs only have properties and getters/setters
  • the same model manipulation code isn’t repeated “everywhere”
  • it’s very clear which classes are responsible for manipulating the model

Background

We have a schema that defines our domain. From that, we generate a “pure” model that consists of simple objects (POJOs) that come from JAXB.

In working with this model, several developers on the team have created boiler-plate code to access and manipulate the model. It is “sprinkled” in many places. Some have created wrapper objects that subclass instances of the model and add functionality. Others have created external utility classes. I’m looking to unify this code so that it’s no longer “sprinkled everywhere.” Ideally, the logic can be contained in a certain class of objects who are clearly responsible for generic manipulations of the model.

Example

Let’s use a grocery store as a generic example. Model objects consist of things like:
Products, Aisle, Shelf, Employee, WorkSchedule, Vendor

Common model manipulations consist of things like:
findManagerWorkingOnDay(day, schedule), findAisleForProduct(apples), countItemsOnShelf(topShelf), product.isModified(), removeProductFromVendor(apples, vendor)

We don’t want to “pollute” our Vendor POJO with a function like removeProductFromVendor. Likewise, we don’t necessarily want to extend every model object, just to add the isModified property just so our GUI can know to “enable/disable” the save button.

Or do we?

Summary

Once a model object is in memory, who should be responsible for manipulating it–for instance, to iterate over a list of “employees on duty today” and find one who is a “manager?”

In these cases, database calls are overkill because we already have everything we need in memory (for ex: we’ve already queried the DataStore and we need to work with the result objects throughout the application). Ideally, this code would be available to any object who had, for example, a list of employees.


In terms of best practice, where is the ideal place to put the static method:
public static Employee findManager(List<Employee> employeesOnDuty);

which would iterate over the list of employees (POJOs) and return the first one where employee.title.toLowerCase().contains("manager")

If a team were to work with this sample object model, several people would write functions like this. What are some of the best practices to capture this responsibility such that POJOs remain “pure” and the same boiler-plate code isn’t “sprinkled everywhere.”

  • 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-05-28T17:59:14+00:00Added an answer on May 28, 2026 at 5:59 pm

    Given that your POJO objects are from a vendor, I understand your reluctance to add functionality to them, and you obviously don’t want code randomly sprinkled around your project.

    Sounds like a job for either a set of Decorator subclasses, or as Ken suggests, facades.

    I like decorators here because you’d then just refer to your vendor pojo by the name of the decorator class, which would then have the added behavior (isModified, searchByName, etc), all in one place.

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

Sidebar

Related Questions

When I download some package sources, (e.g. foo-[ver].orig.tar.gz, foo-[ver].dsc), I often encounter dependencies problem
When working with text in Flash, I often encounter the following problem: http://www.aino.se/media/i/subpixel.png This
Hi i encountered this problem whereby when i initialized my String[], there seems to
I encounter this problem when tackling with virtual inheritance. I remember that in a
did someone else encounter this problem? I use the methods PopUpManager.createPopUp() and PopUpManager.centerPopUp() to
I often encounter problems in terms of design if it comes to this point:
I often find myself reading books and articles that outline patterns, best practices, and
I encounter this problem Fatal error: Uncaught exception 'PDFlibException' with message 'Couldn't find encoding
I encounter this problem : I have a django (python) server that serve XML
I've encountered this problem (while trying to add SQL Server Database (.mdf) file to

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.