Type-safe properties

2 views
Skip to first unread message

hbf

unread,
Jul 9, 2010, 3:59:02 AM7/9/10
to GWT Pectin
Hi,

I have just stumbled over Bindgen [1] and its GWT version [2]. The
library generates from class Foo, say, a class FooBinding that allows
you to access the properties of Foo with set() and get(). (It does not
implement any Observer pattern as the name might suggest.)

Have there been any thoughts of using such a tool to make bindings
like:

public static abstract class PersonModelProvider extends
BeanModelProvider<Person>{}
private PersonModelProvider personProvider =
GWT.create(PersonModelProvider.class);

...
givenName = fieldOfType(String.class).boundTo(personProvider,
"givenName");
surname = fieldOfType(String.class).boundTo(personProvider,
"address.street");

type-safe as in the following pseudo-code?

givenName = fieldOfType(String.class).boundTo(new
PersonBinding().givenName());
surname = fieldOfType(String.class).boundTo(new
PersonBinding().address.street());

Type-safety will ensure at compile time that all you model paths are
correct – a powerful feature.

Kaspar

[1] http://bindgen.org/
[2] http://github.com/stephenh/bindgen-gwt/

Andrew

unread,
Jul 10, 2010, 2:26:50 AM7/10/10
to GWT Pectin
Thanks for the link, I hadn't seen it. Some sort of generated code
like that would be very cool for pectin. To work properly I think it
would need to support change events.

So for the following:
employer =
fieldOfType(Employer.class).boundTo(employeeBinding.employer());
employerName =
fieldOfType(String.class).boundTo(employeeBinding.employer().name());

..calling
employer.setValue(new Employer());

..should cause employerName to fire an appropriate value change event.

Currently BeanModelProvider makes sure this happens since it generates
a graph of nested models.

But I agree something like this would be very nice. I don't have time
to write such a tool at this stage but if you feel like contributing
it would be very welcome. In fact any implementation only needs to
return Value/ListModels and ensure changes propegate through the
hierarchy.

Cheers
Andrew
Reply all
Reply to author
Forward
0 new messages