FX-9: strange (?) factory pattern in BehaviorBase:

fastegal at swingempire.de fastegal at swingempire.de
Fri Mar 18 09:56:12 UTC 2016

The implementation of creating/accessing its inputMap looks strange to me:

// no field

// abstract getter
protected abstract InputMap getInputMap();

// implemented factory method
protected InputMap createInputMap() {
      return new InputMap(getNode());

Now all subclasses (need to) contain the exact same snippets (and we  
all know that code duplication is the worst smell of all :)

// have the field
private InputMap myMap;

// set the field in constructor
myMap = createInputMap();

// implement getter
protected InputMap getInputMap() {
     return myMap;

Wondering why the field is defered to subclasses? If it were pulled up  
into base, all the duplicated code in subclasses could be deleted.

There must be a reason, but I don't see it - please enlighten me!


More information about the openjfx-dev mailing list