Results 1 to 4 of 4
  1. #1
    kez1304 is offline Member
    Join Date
    Jun 2011
    Rep Power

    Default Creating objects with automatic names

    Hi all!!

    Wondering if anyone can shed a little bit of a light on something that has been puzzling me for a little while now.

    I think it's best explained with a verbal example...

    Let's say that I'm designing a program for a client at a GP Surgery. This program needs to have, within its UI, an area to register a new patient, taking various details (name, DOB, sex, etc), and creating two-way links with various other objects (doctors, nurses, etc).

    Now, when this new patient is generated through the various inputs in the UI, how can I name the resulting new objects in a coherent manner. For example, the first patient object generated is called 'patient1', the second, 'patient2', etc.

    Or is this not possible? If that's the case, is it best to add them to a map? With some form of uniquely generated ID instance variable that can then be searched for within the map?

    Any advice, thoughts, comments, assistance, would be greatly appreciated. :)

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Richmond, Virginia
    Blog Entries
    Rep Power


    I don't think you can create dynamic variable names, you can however add them to an ArrayList. If this wasnt what you were asking for, please say so.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    You can get the effect of generated variable names by using a Map. The key would be the generated name: Patent1.

  4. #4
    kez1304 is offline Member
    Join Date
    Jun 2011
    Rep Power


    Thanks guys for your speed replies.

    An ArrayList would do what I was after, but I think a map is indeed better suited.

    I think having a coordinating object to hash their DoB, first and second names into a checksum, and using that as the key with the corresponding object as the value should do the trick. Then I can simply have a lookup interface that their information can be input into, the same algorithm used to create a checksum, then simply match them up.

    Is that something similar to what you would do with this given situation?

    Thanks again for ur replies guys. Really appreciate it. :)

Similar Threads

  1. Creating a list with objects
    By thine_iniquity in forum New To Java
    Replies: 6
    Last Post: 03-25-2011, 03:55 AM
  2. creating dynamic objects?
    By alacn in forum New To Java
    Replies: 4
    Last Post: 06-04-2010, 03:51 AM
  3. creating public objects
    By TaxpayersMoney in forum New To Java
    Replies: 2
    Last Post: 05-19-2010, 06:50 PM
  4. Creating abjects with different names
    By bugger in forum New To Java
    Replies: 3
    Last Post: 11-26-2007, 12:14 PM
  5. Replies: 0
    Last Post: 11-08-2007, 08:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts