Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6192554
Votes 0
Synopsis Need generic factory interface.
Category java:classes_util
Reported Against
Release Fixed
State 3-Accepted, request for enhancement
Priority: 4-Low
Related Bugs
Submit Date 09-NOV-2004
Description
A DESCRIPTION OF THE REQUEST :
One thing I've found to be extremely useful since the introduction of generics into my own APIs is the use of a common factory interface. For example:

public interface Factory<T>
{
    T create();
}

Since the introduction of generics, the API designer can use this interface to accept factories for the repetative or custom creation of typed objects. For example, the API of  a multi-map might be designed using a factory to create the collections that will be used to store multiple values under one key:

public interface MultiMap<K, V, C extends Collection<V>>
extends Map<K, C>
{
    /**
     * Sets the factory that will be used for creating the collections that will
     * store multiple values under each key.
     */
    void setCollectionFactory(Factory<? extends C> factory);

    /**
     * Puts the specified value into the collection that is mapped to the
     * specified key and uses the defined factory to create a new collection
     * if the mapping does not exist.
     */
    void putValue(K, V);
}

The use of the factory allows the developer to define the collection implementation that best fits his needs while the multi-map need not care what type of collection it is.

JUSTIFICATION :
Factories are frequently used to hide implementation details and simplify code. I believe the frequency of use justifies the need to define a common interface.
  xxxxx@xxxxx   2004-11-09 03:52:34 GMT
Work Around
Use java.util.concurrent.Callable<T>.  But the names of the interface and of its single method (call()) are not very informative if in fact you are using it to mean a factory.
  xxxxx@xxxxx   2004-11-29 10:09:46 GMT
Evaluation
N/A
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang