Important Concepts in Component Models

   

JavaBeans provides a platform-neutral component architecture. This is in contrast to platform-specific component architectures such as COM for the Windows platform. A COM component written to be placed inside a corresponding container such as Microsoft Word cannot be used in containers based on other component architectures. Because JavaBeans is an architecture-neutral specification, Beans can be placed into any container for which a bridge exists between JavaBeans and the container's component architecture. This means that a JavaBean can be used in containers as diverse as Microsoft Word, Internet Explorer, and Lotus Notes, among others. To accomplish this seemingly impossible feat, the JavaBeans specification adopts features common with the other popular component models. In particular, these features include the following:

  • Component fields or properties

  • Component methods or functions

  • Events and intercommunication

  • State persistence and storage

Note

If you are familiar with component models already, you don't necessarily need to read this section. You can jump right into the next section, "The Basics of Designing a JavaBean."


Component Fields or Properties

For a component to be useful, it has to have a set of properties that defines its state. For example, if you were to design a component that displayed some text, one of the properties of that component might be the foreground color of the font. Another property might be the type and size of the font. Taken as a whole, the set of properties that make up a component also defines its state. For example, if the properties of one component com-pletely match that of another, they are in the same state.

Properties are often used to define not only the appearance but also the behavior of components . This is because a component need not have any appearance at all. For example, a component in a spreadsheet might calculate the interest earned on some earnings column. If that component is not capable of displaying the data, it probably shouldn't have any properties associated with appearance. It is likely, however, that it will have a property that defines the current interest rate.

Properties can range from Boolean values, to strings, to arrays, to other components. They can also be interdependent. Following the same example given previously, a component that displays the earnings column might want to be notified if the interest rate property of the other component changes.

Component Methods or Functions

The API, so to speak, of a component is the collection of methods or functions that it contains that other components and containers can call. There has to be some way for a container to modify a component's properties, notify it of an event, or execute some functionality.

The various component models differ in how they make the properties and methods of their components available to other components. Because entire books have been written on how this is implemented for different models, it's clear that this is a common feature of component models. This topic will be discussed as it relates to JavaBeans in the section on introspection later in the chapter.

Events and Intercommunication

A component by itself is a lonely component. Although some components might have extensive functionality and many properties, in the true spirit of a component, it should be the most useful when exercised in conjunction with other components. So if two components are sitting together in a container, how do they talk? How does one let the other know when it has done something the other really ought to know about?

The method by which most components communicate is through event transmission. One component (or the container) undergoes some action causing it to generate an event. For example, an event is generated when you click a button. Depending on the model, the component will notify the container, the interested components, or both of the events. At the same time, the objects in the environment also act on events delivered to them. For example, the File dialog box displays itself when it hears that you just clicked a Browse button.

State Persistence and Storage

It is important for components to remember their state. This is so common that you might not even recognize it. When you open an application and it remembers the size and position of its window when it was last closed, it is maintaining (to some degree) a persistent state.

Also important is the capability to store and retrieve components. Sun Microsystems, Inc., likes to call this packaging. This is especially important in a distributed environment where the components are likely to be served up over a network.

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net