Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java MVVM and WPF alternative

Is there a Java alternative to these technologies? I find the data binding capabilities and INotifyPropertyChanged of most use (along with containers and elements of the sort), but the lack of cross-platform of .NET makes me think of Java. What do you suggest? Is there any equivalent product? One that implements XAML?

like image 308
Alvaro Avatar asked Nov 18 '12 21:11

Alvaro


2 Answers

The technology (WPF)

If you are looking for an alternative to WPF for the Java platform you should take a look at JavaFX.

The technology is very similar to WPF in the following ways:

  • The applications user interface is made up of a tree of objects called a scene graph consisting of Node objects (which is similar to the WPF visual tree which consists of UIElement objects).
  • The Pane node and it's derivatives are conceptually similar to the WPF layout panels.
  • The user interface can be created using a markup called FXML which is similar to XAML.
  • JavaFX provides objects that represent properties which support binding and change notification (think dependency properties). Unlike dependency properties they are not tied to the user interface technology so can be used by your model classes.
  • The user interface can be styled using CSS.

Take a look at my answer to the question how does JavaFx compare to WPF which provides a much more detailed (but still high level) comparison of WPF and JavaFX.

The design pattern (MVVM)

The MVVM pattern is a specialisation of the presentation model pattern. It is possible to create a variation of this in JavaFX as the platform provides properties that support binding and the presentation model is basically an object that encapsulates the state of the model and provides operations that act upon that state.

Most examples I have seen though use a variant of the model-view-presenter pattern. Out of the box JavaFX supports a very simple MVP structure where each view is associated with a 'controller' class. This is fine for small applications but doesn't really provide great separation of concerns.

like image 187
Benjamin Gale Avatar answered Oct 05 '22 01:10

Benjamin Gale


Maybe you should keep an eye on the fantastic MVVMFX Framework. Based on the parallels between WPF and JavaFX like descriptive UI declaration (FXML/XAML) they tried to adopt best practices of the development with WPF.

It supports, of course, Databinding concepts and implements the necessary interfaces for notifications between the view, viewModel and the model. UI and its UI-Logic (code behind) is realized with fxml-files (created with Scene Builder) and the obligatory Java class. With many good examples it isn't that hard to understand their concepts because it is a strict implementation of the purest MVVM-Pattern. All you need is to establish the framework in your project dependencies.

like image 40
Namor Egnats Avatar answered Oct 05 '22 01:10

Namor Egnats