Java generics "registry" design pattern

L

laviofer

So here is what I am after:

I want to have a generic class MyClass<T> that holds a data member
ArrayList<T> m_TList

Now, suppose I have a method that reads a file, and has to fill in the
list. The file is a list of strings, and I want to have a registry
class that knows how to turn a string into a T object. T is
"Identifiable" - that is, each object has a unique String ID. I want
the T class to be able to return its (static) Registry object so to
have something like:

public class MyClass<T>
{
public void readFile(String filename)
{
// open file
// get registry of T
Registry<T> registryOfT = ...
// for each line of file
// read String ID
T newObject = registryOfT.getObject( ID );
m_TList.add( newObject )
}
}

The idea is that T can be a person with a social security number ID,
or a part with a unique identifier.

Any ideas?

Thanks, Ofer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

generics puzzle 57
Tree design with generics 2
Generics 24
Generics for a multiplevalue hashmap 8
Hairy generics question 29
Java RMI - registry questions 3
Generics Issue 13
Generics 12

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top