Note that there are some explanatory texts on larger screens.

plurals
  1. POMany classes use an object, but having different views of it
    text
    copied!<p><br /> Sorry for the title, I couldn't think of a more self-descriptive one.</p> <p>In the stand-alone application I'm developing (it's a university assignment) I'm facing this problem:<br /> I've got my entities (or Model objects or Business object etc) which are nothing more than POJOs.</p> <p>Naturally there are (will be) many classes that uses them, but some of these classes should not be allowed to modify their value (e.g. using their setters); we can say that I need to pass an object to different classes with different permissions: read-only to some classes, read-write to others that are allowed to modify the state of the object.</p> <p>An example would be a GUI window that only displays information about the object: I would like to make sure that this class is totally unaware of how modify the state of the object.</p> <p>I read a lot of topics with some related problems (read-only interfaces, read-only implementation, defensive copies, etc...) but I did not find anything suitable for my case.</p> <p>Let's say I would like to <strong>grant access to the setter methods of an object only to specific classes</strong>, but I can't find a way to achieve this.</p> <p>I initially thought that interfaces would be fine (eg <code>ReadOnlyObject</code> with getters and <code>WriteOnlyObject</code> with setters and <code>Object</code> implementing both of them) but the problem is that <code>WriteOnlyObject</code> interface would be easily reachable by any class that uses <code>ReadOnlyObject</code>. Beside that, I'm not convinced that writing interfaces with only getters or setters is a good practice.</p> <p>Please help! @_@</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload