Chapter 3. Models and binding

 

This chapter covers

  • Creating models
  • Creating observable properties
  • Binding data from the model to the view

Any sufficiently advanced technology is indistinguishable from magic, at least according to Arthur C. Clarke. And getting data to automatically update itself in several places with a few simple declarations looks magical at first, but when you learn to identify the process that’s occurring it seems more mechanical than magical.

Why are models used in the MVC framework, and what is their role? Models are to some extent a shared whiteboard, where a controller or a view can update abstract values and respond when it observes a change. The key in these instances is the binding of the data, and to the uninitiated the bindings can appear magical.

To understand and appreciate just how magical the binding support is in Griffon, it’s necessary to go down to the lowest levels of code and see how you would construct these patterns, and then show how the bind calls build on them. It’s like long division: you can teach a child to use a calculator, but if they know how the arithmetic works it seems a lot less magical and is conceptually easier to grasp.

But as with all magic, there are some dues to be paid. Before we dig into how it works, you need to understand why you need to make it work.

3.1. A quick look at models and bindings

3.2. Models as communication hubs

3.3. Observable beans

3.4. Have your people call my people: binding

3.5. The secret life of BindingUpdatable

3.6. Putting it all together

3.7. Summary