commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Chaffee / Purple Technology <>
Subject Re: [collections] Collections Next Gen
Date Wed, 02 Apr 2003 18:05:52 GMT
Yet another option is to put the static creation methods on the class

  Map fooMap = FooMap.createFooMapFor(sourceMap);

I find this much more natural than going through a separate static
utility class.  The ostensible reason for the Java Collections API
putting the creation methods into a separate Collections class was
that you can't add methods to an interface.  Since ProxyMap is not an
interface, we don't have this limitation.

This follows the Factory Method pattern, which is the simplest and
clearest of the Factory family (Factory Method, Factory, Abstract

If you want, you could put the creation methods on MapUtils also, and
have one static call the other.

    public static Map fixedSizeMap(Map map) {
        return FixedSizeMap.createFixedSizeMapFor(map);

Then FixedSizeMap et al. could be promoted from inner to normal public

Also, AFAICT, ProxyMap is only ever useful if you subclass it
(otherwise you'd just use the original map).  Since it thus doesn't
need any public constructors, I see no problem with a protected (not
package!) constructor that has non-standard semantics, as long as any
public ctors are copy constructors like the Collections API says.

(BTW, I'm confused by your example -- SequencedMap is not a ProxyMap...)

All this is IMHO of course.

Alex Chaffee                     
Purple Technology - Code and Consulting
jGuru - Java News and FAQs       
Gamelan - the Original Java site 
Stinky - Art and Angst           

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message