2.1.2.2 Services, Elements, and Features

So what's an application made of? The PEAK approach describes application components in terms of their lifecycles and roles, as follows:

Services

Similar in concept to ``singletons", Services are ``well-known" instance objects which exist for the lifetime of the application. For example, a database connection object in an application could be a service component, and so could a top-level window in a GUI application. J2EE ``session beans" and ``message-driven beans" are also good examples of service components. (Note: don't confuse this general concept of services with the Zope 3 concept of a ``Service"; the latter is an example of the former, but not necessarily the other way around.)

Elements

Elements are typically ``problem-domain" objects or their proxies in the user interface. They are created and destroyed by other Elements or by the application's Services. Typical Elements might be ``business objects" such as customers and sales, but of course any object that is the actual subject of the application's purpose would be considered an Element. In a mail filtering program, for example, e-mail messages, mailboxes, and ``sender whitelist" objects would be considered Elements.

Features

Features are ``solution-domain" objects used to compose Elements, and less often, to compose Services. Features are typically used to represent the properties, methods, associations, user interface views, database fields, and other ``features" of a problem-domain Element. Feature objects are often used as a class attribute in an Element's class, and shared between instances. PEAK makes extensive use of feature objects to implement labor-saving techniques such as generative programming.

This breakdown of application components is called the Service-Element-Feature (SEF) Pattern. PEAK makes it easy to create components of each kind, but this pattern certainly isn't limited to PEAK. You'll find Services, Elements, and Features in almost any object-based application, regardless of language or platform. But, the pattern is often implemented in a rather haphazard fashion, and without the benefit of explicit ``wiring" between components.

When you design an application using the SEF Pattern, your top-level application object is itself a Service. You construct that service from lower-level services, such as database connections, object managers, and maybe even a top-level window object for a GUI application. If your application is to be web-based, or you're constructing a middle-tier subsystem, perhaps it will be composed of web services or the equivalent of J2EE session beans.

The top-level application object may provide various methods or ``value-added" services on top of its subcomponents' services, or it may just serve to start them up in an environment that defines their mutual collaborators. You may find later that what you thought was an ``application" component, is really just another service that you want to use as part of a larger application. Fortunately, it's easy to change a PEAK component's bindings and incorporate it into a larger system.

Defining the Elements of your application design is also fairly straightforward. Elements are the subject of what your application does. A business application might have Customer elements, a web server might handle Page elements, and a hard drive utility might manipulate Partition elements.

Features, on the other hand, are usually provided by frameworks, and incorporated into your application's Elements to create a specific kind of application. For example, a GUI framework might provide visual features that allow mapping Element properties to input fields in a window.

While PEAK does or will provide many Element and Feature base classes you can use to build your applications, these facilities are outside the scope of this tutorial, which focuses primarily on assembling an application's Service components. However, some of the techniques you'll learn here will be as applicable to Element and Feature objects as they are to Service components.

So, let's get started on actually using PEAK to build some components, shall we?