Introspection, Simple, Boolean, Indexed Property, Events: Design Patterns in Java Beans

Introspection: It is a process of examining a Java bean for its capabilities. By using introspection, information about a component can be gathered.

Property: It is a subset of a state of a Java bean. By property values features and look of a component can be determined.

Simple Property: It has only one value.

Design Pattern for Simple Property:

public T getN( );

public void setN(T arg);

where, T is the type of property and N is the name of property.

Read only property can access only get method and write only property can access only set method. Read/Write only property can access both the methods.

Boolean Property: Its value can be either true or false.

Design Pattern for Boolean Property:

public boolean isN( );

public boolean getN( );

public void setN(boolean value);

Indexed Property: It can have multiple values.

Design Pattern for Indexed Property:

public T getN(int index);

public void setN(int index, T value);

public T[ ] getN( );

public void setN(T values[ ]);

Design Pattern for Events: A Java bean can create vents and then send it to other objects. Here are the design patterns for events:

Multicast an event to multiple listeners.

public void addTListener(TListener eventListener);

Unicast an event to only one listener:

public void addTListener(TListener eventListener) throws TooManyListeners;

Listener which doesn’t wishes to receive a type of event notification from a bean:

public void removeTListener(TListener eventListener);

Leave a Reply