2

I was answering a question, where the solution was to use an observable collection like ObservableList. Later I realised that I don't know if the solution is considered as "clean", since using ObservaleList from the FXCollections is like using partly JavaFX but at the same time not using it.

Is it ok to use FXCollections and mixing them with let's say AWT or in the Spring framework or any other framework which has nothing to do with JavaFX?

I did not find any native observable collection API in Java/Kotlin. Is there a library/framework that contains observable collections and would separate them from JavaFX? I have tried looking them up, but I have only found RxJava, which has, from what I understood, nothing to do with the behaviour I want.

To sumarize my question: Is it considered clean using FXCollections in projects that have nothing in common with JavaFX. If not, is there a framework which would produce the same behaviours as observable collections?

0

1 Answer 1

3

Generally speaking, it is a bit of a smell. Introducing a dependency towards a specific (large) framework/component, to then only use a small fraction of technology, that should be done "fully conscious".

You always have to balance between reusing existing code, or by writing it yourself. You shouldn't look at the world like a supermarket, where you walk around and throw whatever thingy into your cart that looks helpful or interesting on a first glance. Build tools like maven make that super easy (just add another entry to your POM file, right), but defining the dependency is the smaller part of this decision! It can have unpleasant consequences later on, down the road.

Having said that, as you are asking about JavaFx specifically, my answer is: avoid doing it.

The problem with JavaFX is: there are plenty of environments that give you trouble when going for JavaFX. I have seen more than once that group A created tooling that was based on JavaFX, to then find that group B couldn't be using that tool because they had to use it on IBM System Z. Sorry, IBM System Z and JavaFX, not a nice story.

Long story short: adding new dependencies to a project needs a clear decision, and you have to make sure that it doesn't cause problems for the people using your delivery. Adding the dependency is done in 5 minutes, but then you made yourself dependent, for the life time of your project! And given the sad story of JavaFX, who knows what will happen to it in 1, 3, 5 years.

4
  • I like your point with the dependencies and the “just another entry in my POM file”! What about any open source libraries for observable collections in java/koltin? Commented Aug 23, 2018 at 8:39
  • Unfortunately, that question is off topic here. We don't recommend libraries, we only recommend to not use them ;-). Seriously: I don't have a good answer for that request.
    – GhostCat
    Commented Aug 23, 2018 at 8:58
  • 1
    JavaFX is modularized. If you know what you are doing, you can use and only rely on its javafx.base module without the rest of the framework. The base stuff like observable properties, collections, binding, and events was built to be independent of all the platform-specific graphical stuff in JavaFX (though that fact is not generally well known or utilized).
    – jewelsea
    Commented Jul 22, 2021 at 21:36
  • 1
    The javafx base implementation is likely the best library for such functionality currently available for Java. Even still, GhostCat's answer is well thought out and argued and still applicable for many applications, so caveat emptor
    – jewelsea
    Commented Jul 22, 2021 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.