Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ValueObject Interface Reference

Inheritance diagram for ValueObject:
[legend]

Detailed Description

Definition of a ValueObject

A ValueObject is a type of object which cannot be explicitly constructed by the user. The class defines a set of different values.

Example Usage

Here are some examples of value object uses:

 IntSet a = IntSet.v(); 
 IntSet b = IntSet.v(5); 
 a = a.union(b); 
 a = a.union(IntSet.v(6)); 
 System.out.println(a); // should print out something like {5, 6} 
 

It's also possible to have multiple subclasses of the same ValueObject.

 given: 
    abstract class Type 
    class IntType extends Type    with IntType.v(); 
    class StringType extends Type with StringType.v(); 
    class ArrayType extends Type  with ArrayType.v(Type t, int dimension); 
 

In this case, there are two type constants, namely IntType.v() and StringType.v(), and one Type which takes two arguments, that is, ArrayType().

Methods of Implementation

There's two different ways of implementing a ValueObject class:

  1. Unique Instance per Value: with this method, each value has a unique object associated with it. This means comparisons are extremely quick because the equals() method which simply use the == operator on the two objects. The downside is that you need to maintain a Hashtable of sorts which is checked every time a value is retrieved with the v() method. Also, memory is not wasted on duplicate objects.

  2. Multiple Instances per Value: with this method, the construction of values is much faster because there is no hashtable to go through. On the other hand, the equals() will be performed more slowly because it will have to construct the structures of both objects, and this method consumes more memory because of possible duplicates. Memory for the value objects will be de-allocated, however, when the objects are no longer in use, whereas the Unique Instance per Value object cannot use the garbage collector to recuperate the unused ValueObjects because there will always be a reference to the object in the Hashtable.

Definition at line 145 of file ValueObject.java.


The documentation for this interface was generated from the following file:
Generated at Thu Feb 7 07:22:52 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001