VisualAge provides beans that enable you to dynamically create and reference bean instances visually. A Factory creates new instances of a bean type, based on a connection from an event to a constructor for the Factory's type. A Variable references any instance of the Variable's type that you assign to it using a connection. With either a Factory or a Variable, you specify the bean type that it can create or reference.
A Factory's type specifies the type of bean instance, or object, that it creates. A Variable's type specifies the type of object that can be assigned to it. For example, if you change a Factory's type to Customer, it can create Customer objects. If you change a Variable's type to Customer, you can use it to reference any Customer object that you assign to it.
You can visually create and access beans in the Visual Composition Editor.
Bean | Description |
---|---|
Factory | A bean that dynamically creates instances of Java beans |
Variable | A bean that provides access to instances of Java beans |
Adding a Factory or Variable bean
Select a Factory or Variable bean from the Other category of the beans palette. Alternatively, you can select a class type as a Variable in the Choose Bean window.
Changing the Factory or Variable type
When you add a Factory or Variable bean from the palette, its initial type is Object. Change the type as follows:
After you change the type, you can make connections to features of the new type.
Creating objects with a Factory
Connect an event to a Factory constructor method. If the constructor you choose requires parameter values, you can provide these values with additional connections or with property settings. Because the Factory references an object that it creates, you can make connections from the Factory'sthis event to methods and properties of the referenced object.
Assigning a bean instance to a Variable
Connect a bean property of the same type as the Variable to the this property of the Variable. This connection assigns the source property to the Variable, and the Variable references the source as a bean instance. If the source bean is the source property, use its this property as the connection source.
You can use two customized variations of this procedure:
You can now make connections to the properties of the Address Variable to access elements of the Customer's address property.
For examples that use a Variable, see the Amortization class in the com.ibm.ivj.examples.vc.swing.mortgageamortizer package, and the AddressView and CustomerView classes in the com.ibm.ivj.examples.vc.customerinfo package. These examples are shipped in the IBM Java Examples project.
Visual bean basics
Composing beans visually
Promotion of bean features
Tearing off properties
Using VisualAge beans in visual composition
Adding the IBM Java Examples project
Factory and variable beans
CustomerInfo sample