JavaFX and the Missing Interfaces

Scott Palmer swpalmer at gmail.com
Wed Nov 7 06:25:51 PST 2012


On Wed, Nov 7, 2012 at 6:02 AM, Randahl Fink Isaksen <randahl at rockit.dk>wrote:

>
> class Node ---- implements ----> interface SceneNode
>
> Since everyone always extend Node (directly or indirectly) you can evolve
> SceneNode with new methods without breaking anything, as long as the method
> is implemented by class Node, and thereby transitively by everyone else.
>

<snip>

Ahem...  You wrote:
InternationalizedNode extends SceneNode {
    void somethingRelatedToI18n();
    ...
}

You have just gone against your own statement of "Since everyone always
extend Node..."

This has the original problem of causing your code to break if a new method
is added to SceneNode.  You would be tying your code to a particular
version of JavaFX such that a user with a newer version won't be able to
run your code.  It works for maintaining consistency with internal classes
of JavaFX, where the interface and the rest of the framework can be
modified in lock-step with each other, but not for the use-case that you
have described.

If you don't inherit the SceneNode interface and just follow your own
advice when implementing your InternationalizedNode you would have:

class MyNode extends Node implements InternationalizedNode {
     void somethingRelatedToI18n() { ... }
    ...
}

Still guaranteeing that you have a real Node but without the need of the
extra interface that just shoots you in the foot.


Scott


More information about the openjfx-dev mailing list