java - How to restrict access to mutable or immutable methods? -


In a new Java project, I try to implement as best practices as possible. Anyone with whom I have a problem is irreversible. Although I understood this concept and had already made some unchanging classes, now I came to a class where I think it is more suitable for doing an ineligible class.

The main problem is that I have unstable parts in some cases of class so that in my case the visual layer of MVC can not directly modify the object, but must go through its controller.

I think 2 ways to do this:

  1. Create an interface "Thing" in which it has all the irreversible methods (read-only) and the interface " MutableThing "which make the setters.

  2. Place all the methods in an interface and restrict the objects to be wrapped in a way that is wrapped in a collection. So that exceptions can be thrown when reaching irreversible methods.

I like the first because I think this cleaner is more well designed, but I have a problem in it. I removed "Listener" (L) and removed Listener (L) in the "Thing" interface so that the scene layer could register itself as a listener for some model objects. But with the two methods in the "Thing" interface, it does not understand itself anymore. Actually there is no method of changing the data, so what data does the audience have the ability to indicate to modify the data? I can put these methods in the "MutableThing" interface, but only the view layer has access to the "Thing" interface and itself can not be registered as a listener.

This is the reason why it is not working due to the audience, is the visual level responsible for actually registering on the model as a listener? If the controller can do it in some way (which has access to "mooting") then there will be no problem, but I do not know how to know it.

What would you suggest?

Thank you!

Why is there an ability to register listeners in an interface, if changes in signal data, Is there no way to change the data?

All interface status is that you can retrieve the following values. This does not mean that the object is irreversible. When the object becomes unstable then it is a good idea to make sure that everyone knows that there are some properties in the invariant objects that can not be your objects (safe for thread safely, cash result etc.). Your object is unstable, you should not pretend that it is irreversible as they move with 1 and add / remove the Thing interface.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -