“ A Java bean is a reusable software component that can be visually manipulated in builder tools.”
Java Bean Tutorials
The JavaBeans Specs are available for d/l at http:// java.sun.com/products/javabeans/docs /
What is JavaBeans?
A Java Bean is a reusable software component that can be manipulated visually in a builder tool
JavaBeans is a portable, platform-independent component model written in the Java programming language, developed in collaboration with industry leaders.
It enables developers to write reusable components once and run them anywhere -- benefiting from the platform-independent power of Java technology.
The goal of JavaBeans is to create a system whereby application developers can take a set of beans from a stock library and wire them together to make a full application
Software Components “ A software component is a unit of composition with contractually specified interfaces and explicit context dependencies only. A software component can be deployed independently and is subject to composition by third parties.” Szyperski ECOOP96
Composition not Inheritance In OO languages, new objects are created from old using the inheritance mechanism. Pluggable components are connected together by composition rather than inheritance. Most of the flexibility of inheritance can be gained from various compositional tactics.
Features of JavaBeans
Support for introspection
so that a builder tool can analyze how a bean works
Support for customization
so that when using an application builder a user can customize the appearance and behavior of a bean
Support for events
as a simple communication metaphor than can be used to connect up beans
Support for properties
both for customization and for programmatic use
Support for persistence
so that a bean can be customized in an application builder and then have its customized state saved away and reloaded later
Persistent Storage
Purpose:
To use existing data formats and plug into OLE or OpenDoc documents (e.g., Excel doc inside a Word doc)
To be “trivial” for the common case of a tiny Bean (by saving its internal state)
Solutions
Externalization : provides a Bean with full control over the resulting data layout.
Serialization : provides an automatic way of storing out and restoring the internal state of a collection of Java objects
All bean must support either Serialization or Externalization
Design Pattern rules Constructors A bean has a no argument constructor Simple Properties public T getN() public void setN ( T value) Boolean Properties public boolean isN() public boolean getN() public void setN(boolean value) Indexed Properties public T getN(int index) public T[] getN() public void setN(int index, T value) public void setN(T[] values)
Coding examples for Properties
public class alden2 extends Canvas {
String ourString = “Hello”;
public alden2() {
setBackground (Color.red);
setForeground (Color.blue);
}
public void setString (String newString) { ourString = newString; }
public String getString() { return ourString; }
public Dimension getMinimunSize() {
return new Dimension (50, 50);
}
}
Bound Properties
Generates notification when a property is changed.
public class propertDemo extends Canvas {
String ourString = “Hello”;
private PropertyChangeSupport changes = new PropertyChangeSupport(this);
0 comments
Post a comment