You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Stephen Colebourne <sc...@btopenworld.com> on 2003/05/07 18:17:53 UTC

[collections] Decorators package design

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

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,
eg.
  Predicated.collection(collection, predicate)
  Predicated.list(list, predicate)
  Predicated.bag(bag, predicate)

Any more options? Any favorites?

Stephen


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