commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Chaffee / Purple Technology <g...@stinky.com>
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
itself:

  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
Factory).

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
classes.

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                               mailto:alex@jguru.com
Purple Technology - Code and Consulting    http://www.purpletech.com/
jGuru - Java News and FAQs                 http://www.jguru.com/alex/
Gamelan - the Original Java site           http://www.gamelan.com/
Stinky - Art and Angst                     http://www.stinky.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message