Main Page Packages Class Hierarchy Alphabetical List Compound List File List Compound Members
ValueObject Interface Reference
Inheritance diagram for ValueObject:[legend]
Detailed Description
A ValueObject is a type of object which cannot be explicitly constructed by the user. The class defines a set of different values.
- There are two ways to retrieve an object with a specific value:
- Use the v() method. This returns a ValueObject with representing the given value (the v() method may have arguments).
- Use an operator method on one or multiple ValueObjects.
- In order to determine if two ValueObject objects have the same value, you must use the equals() method, because two different instances may be equivalent.
- You cannot use constructors to create a ValueObject.
- The fields of a ValueObject are final. They cannot be modified.
- To assign an object x the same value as object y, you simply write x = y.
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:
- 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.
- 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
1.2.10 written by Dimitri van Heesch,
© 1997-2001