|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
COLLECTION - is the generic Collection-type.public interface CollectionFactory<COLLECTION extends Collection>
This is the interface for a factory of Collections. It allows to
abstract from Collection implementations.
A Collection instance can be used for different purposes such as a
set or a list or with different aspects such as a thread-safe collection. If
you write a generic component different users of that component may expect
different aspects of your component and therefore the underlying
Collection.
If you use this interface and allow the user to inject an instance of this interface to override the default, your code will
increase usability.
Why passing a CollectionFactory rather than a Collection
instance to the constructor?
Since java 5 you want to use generics for type-safe code. If these generic
types change slightly over the time of development (e.g. from
Class to Class<?>) you would break
compatibility of the users of your code. Additionally you may want to express
that the Collection should be empty and/or NOT shared with others.
Anyways the interface can obviously NOT guarantee this.
| Method Summary | ||
|---|---|---|
|
create()
This method creates a new Collection instance. |
|
|
create(int capacity)
This method creates a new Collection instance with the given
initial capacity. |
|
COLLECTION |
createGeneric()
This method creates a new instance of the generic Collection type
<COLLECTION>. |
|
COLLECTION |
createGeneric(int capacity)
This method creates a new instance of the generic Collection type
<COLLECTION> with the given initial
capacity. |
|
Class<? extends COLLECTION> |
getCollectionImplementation()
This method gets the implementation of the collection-interface used by this
factory. |
|
Class<COLLECTION> |
getCollectionInterface()
This method gets the interface of the Collection managed by this
factory. |
|
| Method Detail |
|---|
Class<COLLECTION> getCollectionInterface()
Collection managed by this
factory.
Collection interface.Class<? extends COLLECTION> getCollectionImplementation()
collection-interface used by this
factory.
Collection implementation.COLLECTION createGeneric()
Collection type
<COLLECTION>.
COLLECTION createGeneric(int capacity)
Collection type
<COLLECTION> with the given initial
capacity.
capacity - is the initial capacity of the collection.
<E> Collection<E> create()
Collection instance.Collection can NOT be bound
to the generic type <COLLECTION> because of limitations
in Java's generic type system. You need to work on the actual sub-interface
(e.g. ListFactory) to get the proper result type.
E - the type of elements contained in the collection.
createGeneric()<E> Collection<E> create(int capacity)
Collection instance with the given
initial capacity.Collection can NOT be bound
to the generic type <COLLECTION> because of limitations
in Java's generic type system. You need to work on the actual sub-interface
(e.g. ListFactory) to get the proper result type.
E - the type of elements contained in the collection.capacity - is the initial capacity of the collection.
createGeneric(int)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||