4 Replies Latest reply: Apr 30, 2012 6:46 PM by 934109 RSS

    WritableObjectValue vs WritableValue

    934109
      Hello,

      While I was inspecting the javafx.beans.property.Property model, I've found something that is intriguing me...
      WritableObjectValue extends WritableValue but it doesn't add nothing new... It only defines new get/set methods... Aren't those already defined in WritableValue? (getValue/setValue).
      In several Property implementations I've found that get() and getValue(), set(..) and setValue(..) are equivalent. Is there any implementation where those methods behave differently?

      The same thing happens with ObservableObjectValue and ObservableValue.
      Isn't a ObjectValue a Value ? :) Why the redundancy?


      Best regards,

      Paulo

      Edited by: 931106 on Apr 30, 2012 8:54 AM

      Edited by: 931106 on Apr 30, 2012 8:55 AM

      Edited by: 931106 on Apr 30, 2012 8:55 AM
        • 1. Re: WritableObjectValue vs WritableValue
          JohnHendrikx
          They do behave differently sometimes, but only in what types they accept and return.

          For example, SimpleDoubleProperty has these:
          double get();
          void set(double d);
          Double getValue();
          void setValue(Number n);
          • 2. Re: WritableObjectValue vs WritableValue
            934109
            Hi John, thanks for your answer! But...

            These methods:
            double get();
            void set(double d);

            aren't implementing the WritableObjectValue interface... You can't parameterize the WritableObjectValue interface with a primitive type (WritableObjectValue<double>) :)
            And I see that the DoubleProperty is only implementing the WritableValue interface (and not the WritableObjectValue interface).
            This is a quite confusing... I mean, WritableObjectValue extends WritableValue to add two new methods (get/set) that are similar to the ones already defined in it's ancestor (getValue/setValue)?
            I can't see any good reason to have a WritableObjectValue interface... and the javadoc doesn't help answering that question either :/


            Regards

            Edited by: 931106 on Apr 30, 2012 1:51 PM
            • 3. Re: WritableObjectValue vs WritableValue
              JohnHendrikx
              There is no big mystery I think. It does this for all the types; there is also WritableStringValue, WritableBooleanValue, etc.. and finally there is WritableObjectValue (for the parametrized case). It is just consistent.

              For the primitive types, this makes sense as it saves some unneeded autoboxing, but for the Object case it is the same as the existing methods - but it is consistent with the pattern atleast.

              PS.: why is this board blocking me from posting "b o x i n g"

              Edited by: john16384 on May 1, 2012 12:18 AM
              • 4. Re: WritableObjectValue vs WritableValue
                934109
                I see your point. But still... The method names are confusing... get() will return the primitive and getValue will return the primitive wrapper... Oh well... I just need to get used to it... :)

                Thanks and regards!