Designing a good bean is very similar to designing a good
class: it must be usable. In fact, making a bean usable for
visual composition improves its use in handcoding as well. Consider the
following:
- Implement a null constructor.
- Keep your bean small. Minimize dependencies on other beans and
classes.
- Implement the java.io.Serializable
interface.
- For visual beans, subclass from
java.awt.Component or one of its subclasses.
- Make important functions available through settable properties. If
necessary, provide a custom editor to make setting properties easier.
Avoid dependencies upon the order in which properties are set.
- Mark interface features in BeanInfo to optimize clarity:
- Set preferred to true for those features that most
people will use.
- Set expert to true for those properties that most
people will never use.
- Set hidden to true for those properties that must
not be used in connections.
- Set Design time property to false for those
properties that you do not want surfaced in the beans property sheet.
- To take advantage of reflection, follow standard design patterns for
methods, events, and properties. Do not use the same set method names
for different properties. Provide a BeanInfo class with meaningful
display names and descriptions.
- Set up bound properties where appropriate. However, be careful not
to overdo it, because property events are multicast through
PropertyChangeEvent, which can affect performance.
- Have your bean signal events for significant state changes. Use
unique event classes instead of a single event class with a flag in
eventData.
- Provide .gif files so that the bean can be represented in the
Visual Composition Editor. Include both 16x16 and 32x32 versions, with
transparent backgrounds.
- To minimize the number of connections during visual composition, specify
several methods with a small number of parameters rather than a single method
with many parameters.
How Classes and Beans Are Related
Use of Visual Beans Created in Other Tools
Defining Bean Interfaces for Visual Composition
Enabling Custom Edit Support for Your Bean
JavaBeans specification
