Documentation, more, more

Dustin Sallings dustin at spy.net
Thu Sep 11 06:04:42 UTC 2003


On Wednesday, Sep 10, 2003, at 21:54 US/Pacific, Richard A. O'Keefe 
wrote:

> If I want something that is like a Java Vector but has a few more
> operations, and I want it to be usable anywhere a Vector is usable,
> then it *has* to be a subclass of Vector.  You can do this in Java 1.2,
> but you had better know everything about Vector.  (One machine here has
> /usr/java1.2/src.jar, another machine doesn't.  Too bad about anyone
> trying to extend Vector on the second machine, eh?)  But if you want
> to make something like an OrderedCollection but somewhat different,
> you DON'T have to subclass OrderedCollection, you can start there or
> anywhere above it in the class hierarchy, even Object, as long as you
> implement all the necessary methods.

	That's a different model.  Source code is not required for extending 
classes in Java.  Vector is a stable (though old and what should be 
considered deprecated) API that can certainly be extended.

	I've extended various parts of the Collections API with good reason 
and without source.  Java has a neat concept in formal protocols.  If 
you want to implement the Map interface in such a way that it keeps up 
with how long it's been since it was last accessed, it's very easy to 
subclass HashMap and override the parts you care about.

	If you want to override Vector to print itself with the size, I don't 
have to know everything about Vector, I just have to do this (no, this 
isn't *exactly* how I'd do it):

	public class MyVector extends Vector {
		public String toString() { return("{MyVector with " + size() + " 
elements}"); }
	}

--
SPY                      My girlfriend asked me which one I like better.
pub  1024/3CAE01D5 1994/11/03 Dustin Sallings <dustin at spy.net>
|    Key fingerprint =  87 02 57 08 02 D0 DA D6  C8 0F 3E 65 51 98 D8 BE
L_______________________ I hope the answer won't upset her. ____________



More information about the Squeak-dev mailing list