K
K
Kirill Saksin2015-03-04 22:05:20
Java
Kirill Saksin, 2015-03-04 22:05:20

How to cook Java SE + MVC + SWING + DependencyInjection/IoC?

Background
I decided that it was time to move from web development in PHP (Symfony) to Java.
There was an idea to write something in Swing, and according to all the canons of OOP, and absolutely correctly.

Problem
A heavy degree of dependence on the correct organization of dependencies, as a result, dependence on DependencyInjection and MVC / MVP / MVVM + personal deep conviction that the Model and View are independent components (i.e. the Controller depends on the Model and on the View, the Model is independent, the View is independent ).

Questions

  1. How to organize MVC/MVP/MVVM, but without the Controller+View\Model+Controller mixes?
  2. How to mix this with DependencyInjection?
  3. Are there ready-made solutions for this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bromzh, 2015-03-10
@bromzh

What does it mean, according to all the canons of OOP? Java is very far from the correct OOP approach, if only because not everything there is an object. Yes, and within the framework of Java itself, there are several different styles. It is necessary to write not according to the canons, but on the basis of the task.
1) 1 , 2 . This is classic MVC, with active models that contain all the business logic. When the model is updated, it notifies all listener views. When an event occurs in the view, it calls notifies the controller, it calls the necessary methods of the model. In web MVC is wrong.
2) Why? The mistake of many beginner Javasts is to use DI where it is not needed. In the JavaEE world, DI is a common occurrence, because the beans are managed there: the application server launches the application in the container, regulates the context and lifetime of the beans, can provide its own API implementations, etc. But in swing applications, there is nothing like that, the program is launched through the main method, all API implementations are included in the final jar, there is no need to track the lifetime of the bins ... It is quite possible to get by with simple configs + factories / builders to regulate dependencies. Although if you really want, then here , for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question