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 7516883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:16:30+00:00 2026-05-30T01:16:30+00:00

I have a Java application where the domain layer is decoupled from the UI

  • 0

I have a Java application where the domain layer is decoupled from the UI by controllers. The problem is that these controllers can return domain objects, and can have domain objects as parameters.

Some of these returned domain objects are mutable, and this is what I want to prevent. I want it impossible for the UI (or future UI’s) to directly modify the domain without accessing the controllers.

I tried two options:

  • In the first one I made sure that each class implemented an ‘Unmodifiable’ interface which contained only getters. And if I needed to return an object to the UI, I returned its ‘Unmodifiable’ interface. So that the UI could only view the getters.
    The problem with this that they still can be cast easily to the original object and access is gained. At first I thought that this level of security was good enough, but it happend that someone accidentally casted some objects and used them in an incorrect way, and integrity was breached.

  • In the second one I tried to provide unmodifiable wrappers for each object that could be returned. But the problem is that these returned objects can be used as parameters for methods in the controllers and so they needed to be unwrapped in the controllers. I tried to make the uwrap() methode package-private, but then I have to put every specific wrapper class in the same package with the controllers and this is a bit inconvenient.

EDIT: 3th option:

  • (With thanks to vic) In the third option the object is wrapped by a unmodifiable wrapper, but can’t be unwrapped by this wrapper. Each Unmodifiable is linked to its modifiable object in a Hashmap. So ‘unwrapping’ is done by getting the modifiable object that is linked to the unmodifiable object.

Does anyone know or has some ideas on how to make objects unmodifiable so they can be returned by a controller, and make it possible to make them modifiable again when they are passed back to the controllers?

  • 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-30T01:16:32+00:00Added an answer on May 30, 2026 at 1:16 am

    What if the controllers store privately the mutable versions of the objects and return immutable versions of it to the “outer world”. The mutable versions will have some kind of unique id, and the controllers will be able to unwrap it by looking up in a Collection of some sort.

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

Sidebar

Related Questions

I have a Java enterprise application that provides a web service, has a domain
Problem Domain: I am working on a new revision of a Java application that
I have a Java EE application and I use Hibernate. The domain objects, I
I have a Java application that launches another java application. The launcher has a
I have a Java application that monitors a folder for incoming XML files. When
I have a Java application that's very String-heavy - it takes a feed of
I have a java application that has Web Services published using Axis. With the
I have a java application that is connected to a view on a remote
We have a Java application that needs to be brought to the foreground when
I have a Java application that I need to integrate our existing PHP website

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.