As an representation of quantities that interact and change over time, the properties/observers/events model is far from being the only game in town. Anyone who's run into issues with the event dispatch thread can attest to weaknesses in the approach.
There's a brilliant (if lengthy) presentation on the topic by Rich Hickey (Clojure author) here: http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey <http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey>It's also worth checking out the recent "deprecating the observer pattern" here: http://lambda-the-ultimate.org/node/4028 <http://lambda-the-ultimate.org/node/4028>Or just run a search on "Functional Reactive Programming" The basic idea is that something like window.height isn't a `property` that you can register events on, and have notifications pushed whenever it changes. Instead, "height" is just a stream of integers, that can be passed around like any other variable. You can iterate over this stream, and the iteration blocks until a new value appears. The best part of this approach is that streams can be composed and filtered, so you could take window.height, and subtract splitbar.position to yield a new stream (operator overloading and closures help here) The result, also a stream, can then be assigned to the height of a panel in a window layout. As designs go, it's kinda elegant. On 18 September 2010 20:25, Reinier Zwitserloot <[email protected]> wrote: > Indeed, Tor. Properties doesn't just mean "nice sugar so I can make x > = 0 really mean setX(0)". It also means seamless support for > propagating changes, including the ability to bind two properties > together. > > I find JavaFX's solution particularly elegant, and when we get around > to adding property support to lombok, we're likely going to pattern it > around that and not the beans jsr. > > On Sep 18, 7:37 pm, Tor Norbye <[email protected]> wrote: > > Right. Just to expand a bit further on this: A field plus a getter and > > setter isn't -really- what we mean when we say we want -proper- > > property support in the language. Think of a GUI component instead, > > such as as a slider. I want -client- code to be able to do this: > > > > slider.min = 0; > > slider.max = 100; > > slider.value = 50; > > .... > > // and to read slider: just reference slider.value > > textBox.content = bind Integer.toString(slider.value); > > > > This can't just be a public field because things need to be organized > > such that when you set the property the UI representation of the > > component updates itself. > > > > With old JavaBeans this was done with special code in the setters > > which would fire property change listeners (that the view listeners > > listen for). With JavaFX properties are directly supported in the > > language so it's using various bind-machinery to handle this. > > > > The point is that for real properties you can't just use a field; in > > Java you need to use proper setters -- which means you don't get the > > nice uniform access shown above. In languages that support properties > > this works nicely. > > > > -- Tor > > > > On Sep 18, 7:15 am, Cédric Beust ♔ <[email protected]> wrote: > > > > > > > > > On Sat, Sep 18, 2010 at 1:30 AM, Steel City Phantom < > [email protected]>wrote: > > > > > > you can implement that today in java. its very easy to do so as > well, > > > > heres how > > > > > > public class haha { > > > > public String name; > > > > } > > > > > > there, now you can do your a.name = foo. not very hard. > > > > > Please reread my post more carefully. If one day you decide to add a > setter, > > > clients of your code who wrote "a.name=foo" won't go through that > setter. > > > > > -- > > > Cédric > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<javaposse%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > > -- Kevin Wright mail / gtalk / msn : [email protected] pulse / skype: kev.lee.wright twitter: @thecoda -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
