2.1.1.1 Implementing Components in Python and PEAK

In the Python language, components are Python objects, and composition and association relationships are represented using objects' attributes. Using the peak.binding package, you'll create attribute bindings that define what sub-objects will be created (via composition) or external objects will be referenced (via association) by each attribute of a component.

Of course, there are some important differences between software and the real world. In the real world, we have to actually build every part of the car ``ahead of time", and we must have one screw for every place a screw is needed. In software, classes let us define the concept of a ``screw" once and then use it as many times as we want, anywhere that we want.

Also, with PEAK, bindings are ``lazy". What this means is that we can define an ``engine" class whose parts aren't actually created until they're needed. We just list the parts that are needed and what attributes they'll be bound to, and when the attribute is used, the part is automatically created or connected, according to our definition.

Since each part ``magically" appears the first time we want to use it, it's as though it was always there. It's as if your car was an empty shell until you opened the door or looked in the window, at which point all the contents magically appeared. And then when you got into the car, the radio was just an empty shell until you tried to turn it on, at which point all of its internal components sprang into being and wired themselves together.

This ``lazy" construction technique can speed startup times for applications which are built from large numbers of components, by not creating all the objects right away, and by never creating objects that don't get used during that application run.