JavaFX and the Missing Interfaces
Richard Bair
richard.bair at oracle.com
Mon Nov 5 12:42:40 PST 2012
> Maybe somebody can show how this would work in more concrete terms? I don't even see how it would be practical at all.
>
> As in how it would be used by end developers and to what benefit, or as in how to make it workable in the current JFX codebase?
The problem is that we cannot add new methods to an interface in a subsequent release. If we were to do so, then although all running binaries would still work fine (assuming you don't mix 'n match newer code with older libraries that don't support the new methods), any code that was implementing the interface would need to be modified at compile time. So for example, Randahl has MyRectangle implementing the SceneRectangle interface but not extending from the Rectangle class. We add some method to SceneRectangle in 8.1. He now has to modify his code when he tries to compile with 8.1 to implement this new method. This level of source incompatibility is not allowed on JavaSE.
The normal course of affairs is to therefore have SceneRectangle2 with the new method and have Rectangle implement both SceneRectangle and SceneRectangle2. And so on. And we are guaranteed to then have a great multitude of interfaces over the course of the next 10 years.
There are a very few places where the likelihood of future changes is minor and an interface could have been used. But in the whole we consciously avoided the use of interface in most places whenever possible, because without defender methods (which were not even considered at the time and won't be available until 8 and have their own set of caveats and are not universally useful) there is no way to evolve an interface over subsequent releases without source incompatibility.
In addition, note that Parent returns concrete Node's, and couldn't be changed to return the interfaces, so it isn't clear to me that there is any benefit to having interfaces at this point in time anyway.
Not to mention having both interfaces and concrete classes in such cases increases the class count, in some cases significantly (depending on how far it was taken).
So my question was, how would using interfaces in an API designed for extension (such as the scene graph -- or any GUI toolkit, really, with a deep class hierarchy) be workable? I'm not aware of it ever being done successfully in such cases, whereas every example I know of uses a concrete class hierarchy for such a design. Not that I particularly care what has been done before if it could be done better, but I don't see how using interfaces helps. It really comes down to evolution -- interfaces don't allow for it. At least, not without introducing a lot of noise.
Richard
More information about the openjfx-dev
mailing list