Basic DataBeans

DataBeans are objects that are used to carry a logical collection of data from one Java or system context to another, including from one machine to another.  For example, they may be used to carry variables that represent the fields in an HTML form from one method, class, and/or machine to another. 

DataBeans are not a well-defined Java class, but, rather, they are a generally agreed-upon architectural convention.  There are four generally accepted properties and several others that are often found.  First, they are serializable, since they are primarily used to carry data between processes or across a network.  Second they have a no argument constructor, which they may inherit from Java Object. Third, variables used to carry data are declared to be private, with the result that, fourth, the bean includes public getter and setter methods to provide access to their values. 

Two other functions are often associated with DataBeans.  First, they may provide verification methods to validate a field's data type or relations among fields, such as matching entries for a password field and a password confirm field.  Second, they often provide mapping functions, such as between a String protocol and a Java Object or between the database form of a data value and the form used in a view (e.g., a date).   If the bean provides mapping functions, it may have a constructor for mapping one direction and a "getMappedForm" (e.g., getXml)  method for mapping the other way. 

At a slightly more general level of consideration, DataBeans should be complete; that is, they should carry all of the information necessary for the called method to carry out its operation.  For example, if the operation is a database update, the DataBean should carry all of the fields to be updated or carry back all of the values returned by a search.

The discussion below considers two examples of DataBeans.  The first is concerned with data associated with login procedures, the second with communication between a client Apple and a Servlet server.


Class DataBean

Basing DataBeans on a common superclass is desirable.  Frequently used components, such as a database id, dateCreated and dateModified, and other similar properties can be defined and their getters and setters implemented in the superclass instead of DataBeans for individual clustes of data.. 


Login DataBean

Logging into systems and updating/managing logins are pervasive tasks for Web-based systems.  This example considers a DataBean that extends DataBean, is simple, but can be used for several different login-related functions.  It also illustrates the use of validation methods.  It is primarily concerned with the mapping between HTML Forms and Java M - V -  C designs. 


Collection DataBean

Whereas most DataBeans are used to transport data for a single instance of a data object, such as user data for registration and/or login or the data describing a product for sale, some functions require as an input parameter or produce as an output result data for multiple instances of an object.  A common example is a database search that returns data from multiple rows, each of which would normally be transported within a single DataBean.  Handling such collections of data can be greatly facilitated by using a CollectionBean.


Client - Server Communication DataBean

Client - Server architectures are most frequently implemented using String protocols.  That is, some character sequence is defined such that it can be parsed, normally into header and body sections, and individual data values extracted, frequently in the form of attribute/value pairs.  However, if communication is known to be between two Java objects (i.e., client and server), a serialized Java object (e.g., a DataBean) can be passed between the two, often resulting in less processing than that required for a protocol string.  This example explores such a use of DataBeans.