Java generics "registry" design pattern

Discussion in 'Java' started by laviofer@gmail.com, Jul 31, 2008.

  1. Guest

    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.
    , Jul 31, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HK
    Replies:
    1
    Views:
    3,595
    Cowboy \(Gregory A. Beamer\)
    Apr 1, 2004
  2. Replies:
    0
    Views:
    725
  3. Pallav singh
    Replies:
    0
    Views:
    339
    Pallav singh
    Jan 22, 2012
  4. Pallav singh
    Replies:
    0
    Views:
    385
    Pallav singh
    Jan 22, 2012
  5. Pallav singh
    Replies:
    1
    Views:
    439
    Peter Remmers
    Jan 22, 2012
Loading...

Share This Page