Best way to interact between views?

In a Swing app, the best way to send data (interaction) between two views?

Looking at the communication session in SCJP 6 Study Guide , he says:

All non-trivial OO applications are a combination of many classes and interfaces work together. Ideally, all interactions between objects in the OO system should use the API, in other words, contracts, corresponding classes of objects.

If I understood this correctly, the best way would be to create interfaces (contracts) for each view and, if necessary, use these interface methods to extract data. Is this a good way? Have a good time creating many interfaces to say what is visible on the screen, ok?

Another way that I think is to have classes for storing data (models) of the view. In this case, is this a good approach to accessing directly these classes of models?

Thanks in advance.

+6
source share
2 answers

The concept of a separable model pervades Swing, as indicated in the Swing Architecture Overview . Typically, each model is represented by an interface; some of them include AbstractXxxModel with some basic event plumbing; and many of them have DefaultXxxModel with a standard implementation.

+6
source

It completely depends on what design you are doing. There are times when the design choice we offer is best for viewing data sharing, but it destroys another aspect of your software. Therefore, to balance, you make a design choice to make your application smooth.

I personally prefer the MVC design pattern. It works for me every time! more about MVC:

Model View Controller

Good luck

Note. In MVC, two views never interact with each other, but use controllers to get data from the model, and basically each view has controllers with a link to this data model.

+3
source

Source: https://habr.com/ru/post/910856/


All Articles