00001 package ca.mcgill.sable.util; 00002 00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00004 * SableUtil, a clean room implementation of the Collection API. * 00005 * Copyright (C) 1997, 1998 Raja Vallee-Rai (kor@sable.mcgill.ca). * 00006 * All rights reserved. * 00007 * * 00008 * This work was done as a project of the Sable Research Group, * 00009 * School of Computer Science, McGill University, Canada * 00010 * (http://www.sable.mcgill.ca/). It is understood that any * 00011 * modification not identified as such is not covered by the * 00012 * preceding statement. * 00013 * * 00014 * This work is free software; you can redistribute it and/or * 00015 * modify it under the terms of the GNU Library General Public * 00016 * License as published by the Free Software Foundation; either * 00017 * version 2 of the License, or (at your option) any later version. * 00018 * * 00019 * This work is distributed in the hope that it will be useful, * 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00022 * Library General Public License for more details. * 00023 * * 00024 * You should have received a copy of the GNU Library General Public * 00025 * License along with this library; if not, write to the * 00026 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * 00027 * Boston, MA 02111-1307, USA. * 00028 * * 00029 * To submit a bug report, send a comment, or get the latest news on * 00030 * this project and other Sable Research Group projects, please * 00031 * visit the web site: http://www.sable.mcgill.ca/ * 00032 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00033 00034 /* 00035 Reference Version 00036 ----------------- 00037 This is the latest official version on which this file is based. 00038 The reference version is: $SableUtilVersion: 1.11 $ 00039 00040 Change History 00041 -------------- 00042 A) Notes: 00043 00044 Please use the following template. Most recent changes should 00045 appear at the top of the list. 00046 00047 - Modified on [date (March 1, 1900)] by [name]. [(*) if appropriate] 00048 [description of modification]. 00049 00050 Any Modification flagged with "(*)" was done as a project of the 00051 Sable Research Group, School of Computer Science, 00052 McGill University, Canada (http://www.sable.mcgill.ca/). 00053 00054 You should add your copyright, using the following template, at 00055 the top of this file, along with other copyrights. 00056 00057 * * 00058 * Modifications by [name] are * 00059 * Copyright (C) [year(s)] [your name (or company)]. All rights * 00060 * reserved. * 00061 * * 00062 00063 B) Changes: 00064 00065 - Modified on June 15, 1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*) 00066 First release of this file. 00067 */ 00068 00069 /** 00070 * <h3>Definition of a ValueObject</h3> 00071 * 00072 * <p>A ValueObject is a type of object which cannot be explicitly constructed by the user. 00073 * The class defines a set of different values. 00074 * 00075 * <p> 00076 * <ul> 00077 * <li>There are two ways to retrieve an object 00078 * with a specific value: 00079 * 00080 * <ol> 00081 * <li>Use the v() method. This returns a ValueObject with representing the given value 00082 * (the v() method may have arguments). 00083 * <li>Use an operator method on one or multiple ValueObjects. 00084 * </ol> 00085 * 00086 * <li> In order to determine if two ValueObject objects have the same value, you must use the 00087 * equals() method, because two different instances may be equivalent. 00088 * 00089 * <li>You cannot use constructors to create a ValueObject. 00090 * <li>The fields of a ValueObject are final. They cannot be modified. 00091 00092 * <li>To assign an object x the same value as object y, you simply write x = y. 00093 * </ul> 00094 * 00095 * <h3>Example Usage</h3> 00096 * 00097 * <p>Here are some examples of value object uses: 00098 * 00099 * <pre> 00100 * IntSet a = IntSet.v(); 00101 * IntSet b = IntSet.v(5); 00102 * 00103 * a = a.union(b); 00104 * a = a.union(IntSet.v(6)); 00105 * 00106 * System.out.println(a); // should print out something like {5, 6} 00107 * </pre> 00108 * 00109 * <p>It's also possible to have multiple subclasses of the same ValueObject. 00110 * 00111 * <pre> 00112 * given: 00113 * abstract class Type 00114 * 00115 * class IntType extends Type with IntType.v(); 00116 * class StringType extends Type with StringType.v(); 00117 * class ArrayType extends Type with ArrayType.v(Type t, int dimension); 00118 * </pre> 00119 * 00120 * In this case, there are two type constants, namely IntType.v() and StringType.v(), and one 00121 * Type which takes two arguments, that is, ArrayType(). 00122 * 00123 * <h3>Methods of Implementation</h3> 00124 * 00125 * <p>There's two different ways of implementing a ValueObject class: 00126 * 00127 * <ol> 00128 * <li>Unique Instance per Value: with this method, each value has a unique object associated 00129 * with it. This means comparisons are extremely quick because the equals() method which simply 00130 * use the == operator on the two objects. The downside is that you need to maintain a Hashtable 00131 * of sorts which is checked every time a value is retrieved with the v() method. Also, memory 00132 * is not wasted on duplicate objects. 00133 * 00134 * <li>Multiple Instances per Value: with this method, the construction of values is much 00135 * faster because there is no hashtable to go through. On the other hand, the equals() will 00136 * be performed more slowly because it will have to construct the structures of both objects, and 00137 * this method consumes more memory because of possible duplicates. Memory for the value objects 00138 * will be de-allocated, however, when the objects are no longer in use, whereas the Unique Instance 00139 * per Value object cannot use the garbage collector to recuperate the unused ValueObjects because 00140 * there will always be a reference to the object in the Hashtable. 00141 * </ol> 00142 00143 */ 00144 00145 public interface ValueObject 00146 { 00147 }