img
Advantages of Java Beans
The following list enumerates some of the benefits that Java Bean technology provides for
a component developer:
· A Bean obtains all the benefits of Java's "write-once, run-anywhere" paradigm.
· The properties, events, and methods of a Bean that are exposed to another application
can be controlled.
· Auxiliary software can be provided to help configure a Bean. This software is only
needed when the design-time parameters for that component are being set. It does
not need to be included in the run-time environment.
· The configuration settings of a Bean can be saved in persistent storage and restored
at a later time.
· A Bean may register to receive events from other objects and can generate events
that are sent to other objects.
Introspection
At the core of Java Beans is introspection. This is the process of analyzing a Bean to determine
its capabilities. This is an essential feature of the Java Beans API because it allows another
application, such as a design tool, to obtain information about a component. Without
introspection, the Java Beans technology could not operate.
There are two ways in which the developer of a Bean can indicate which of its properties,
events, and methods should be exposed. With the first method, simple naming conventions
are used. These allow the introspection mechanisms to infer information about a Bean. In
the second way, an additional class that extends the BeanInfo interface is provided that
explicitly supplies this information. Both approaches are examined here.
Design Patterns for Properties
A property is a subset of a Bean's state. The values assigned to the properties determine the
behavior and appearance of that component. A property is set through a setter method. A
property is obtained by a getter method. There are two types of properties: simple and indexed.
Simple Properties
A simple property has a single value. It can be identified by the following design patterns,
where N is the name of the property and T is its type:
public T getN( )
public void setN(T arg)
A read/write property has both of these methods to access its values. A read-only property
has only a get method. A write-only property has only a set method.
Here are three read/write simple properties along with their getter and setter methods:
private double depth, height, width;
public double getDepth( ) {
return depth;
}
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home