Results 1 to 3 of 3
  1. #1
    Boomn4x4 is offline Member
    Join Date
    Nov 2011
    Posts
    18
    Rep Power
    0

    Default Better way to do arrary list of simple Classes

    I've got three classes AppReply, AppDetail, AppTrace.

    AppDetail and AppTrace are both simple as they only have private members with gettter and setter methods.

    AppReply has members that include array lists of AppDetail and Apptrace
    Java Code:
    public class AppReply{
      private String host;
      private Striing app
      private ArrayList<AppDetail> appDetail = new ArrayList<AppDetail>();
      private ArrayList<AppTrace> appTrace = new ArrayList<AppTrace>(); 
    
      public void setAppDetail(AppDetail d){
         appDetail,put(d);
      }
    
      etc. etc. etc.
    }
    This works out pretty, but it seems a bit of an over kill to have to create and maintain seperate class files especially since this AppReply is the only class that will ever use them. Is there a better way to do this and accompolish the same thing? Maybe using Maps or Vectors (both of which I'm unfamilar with but glad to learn)

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Better way to do arrary list of simple Classes

    You said AppReply is the only class that will use them. But somewhere outside the AppReply they must get created. What is their purpose?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Better way to do arrary list of simple Classes

    If you don't want to maintain separate files for public classes, then make them inner classes (public static) of the AppReply class. It is appropriate since they are apparently closely tied to that class.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Linked List implementation of various classes
    By the_rider9 in forum New To Java
    Replies: 2
    Last Post: 05-21-2011, 03:12 AM
  2. A problem for put the file info to arrary
    By l0afer in forum New To Java
    Replies: 11
    Last Post: 03-28-2011, 06:48 AM
  3. how to send scanned in arrary to class?
    By j@v@ in forum New To Java
    Replies: 3
    Last Post: 12-07-2010, 10:06 AM
  4. Deleting instances of classes from a list
    By Gmurph03 in forum New To Java
    Replies: 8
    Last Post: 11-27-2009, 11:41 AM
  5. How 2d Pixel Arrary Is Stored In .txt/.dat File
    By Mazharul in forum New To Java
    Replies: 1
    Last Post: 08-18-2008, 12:23 PM

Posting Permissions

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