commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <>
Subject [collections] Decorators package design
Date Wed, 07 May 2003 16:17:53 GMT
I have run into a small problem with the initial design of the new
decorators package. (A break out of the inner classes in XxxUtils).

I have put a static factory method on each of the new classes
  public static Type decorate(Type type)
where Type is the collection type.

However this gives a problem when using the class, as the static factory
methods are inherited. Thus, bringing up an auto-complete (Eclipse/other
IDE) on UnmodifiableSortedBag gives a choice of methods taking a Collection,
a Bag and a SortedBag - one from each of the superclasses. This is very

Possible solutions:
1) Copy all the code into each class so the inheritence hierarchy can be
removed. Doesn't solve the problem if someone else subclasses a decorator.

2) Remove the factory methods and make the constructors public.
  new PredicatedCollection(collection, predicate)

3) Add additional static classes that provide the relevant static methods,
  Predicated.collection(collection, predicate)
  Predicated.list(list, predicate)
  Predicated.bag(bag, predicate)

Any more options? Any favorites?


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

View raw message