0

the JavaFX in the title is put into brackets, as the desired answer to this question applies to any object-oriented GUI Toolkit. For me, it is JavaFx, not because I love working with FXML-files and css (I actually code nearly every layout directly by myself instead of using FXML), but because I started to work on my Project in C# with WinForms and wanted to be able to provide my program to OSX-users.

The situtation: The program itself is a kind of Digital Audio Workstation or DAW with the classical elements of track-based editing, some cursor following the tracks that are stacked on top of each other as the music plays, some panels for editing a certain track and adding effects. All of these elements (every single track, every panel with some settings, the silder to move the displayed time interval of the tracks) are selfmade UI-classes that inherit from an Anchor Panel or a VBox or sth. like this ... They manage their own data and how this is displayed. Communciation between these elements is, especially for this kind of application, unavoidable.

Example: The silder to choose which part of the track is shown has to communicate with the VBox containing the tracks as well as with the tracks as they have to manage which elements on the track are shown. For those, who don't know how DAWs look, just an example here

The problem: All of this works pretty well, but the more distinct UI Elements (such as an effect editor, a track manager, setting panel, export panel) I have, the more confusing the code gets inside the elements, that have to communicate a lot with other elements to manage their data, look and behaviour.

What I hope for: Simply spoken: a smart way to manage all those dependencies while still maintaining encapsulation of the single UI Elements. My current code works, but it is a wild mix of ideas I had to manage those problems like using Interfaces or directly accessing one UI Element from another by giving each element a reference to the other elements it depends on. I simply want to cleanse my code and have a fixed scheme on how to deal with those dependencies before I continue putting new features into my program.

A minimal example that could be taken to answer my question would be: I have an AnchorPane that contains a panel with some settings and a VBox with my tracks. If I click "add Track" in the settings, a track should be added to the Vbox. The other way around, if I delete a track via right-click & context menu, The settings panel should show a number of n-1 instead of n tracks now. For both operations, the track has to know about the settings panel and the settings panel has to be able to access the tracks or at least the VBox.

I hope this didn't get too long and I am looking forward to your answers.

Best regards

Hendrik
  • 91
  • 6
  • 3
    "They manage their own data and how this is displayed." This is the beginning of the problem. The data should not be stored in UI components. Use a MVC approach, where the data is factored out into separate classes (the "model") which have no knowledge or reference to any UI. "Communication between these elements is, especially for this kind of application, unavoidable." If you move the data to separate classes, all the controllers/views can observe the data and modify it independently, and there is no longer any need for them to communicate. See https://stackoverflow.com/q/32342864 – James_D Apr 13 '18 at 11:42
  • In the examples I have seen, each component had it's own model, view and controller. If each distinct element has a controller, the same problem occurs. So do I have an extra controller for a group of elements AND the single element controller or just the controllers I really need? (And thank you very much for the answer :) ) – Hendrik Apr 13 '18 at 11:57
  • 1
    The model represents the data. So if two or more components need access to the same data, they should share the same model. In the example I linked, there are three controllers (with corresponding views) that all reference the same model. All the components should be independent; they should not have references to any other components - they should just reference the model. – James_D Apr 13 '18 at 12:36
  • Thank you very much! Can you recommend any literature or web tutorial considering MVC? The ones I have seen describe MVC for a single UI element and not for a more complex structure with some communicating elements ... – Hendrik Apr 14 '18 at 09:26

0 Answers0