Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Regarding good coding practices

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Regarding good coding practices

    Hi folks,

    I wanted to get your opinion around following situation:-
    I have an object with a name nmsArray<CrossConnect>[] ,array of CrossConnect type object. CrossConnect object has some 15 attributes and corresponding getters and setters.
    This array need to be passed to a private method createRoute(someObj<CrossConnect>[]), which as of now uses only 2 attributes out of 15 of the CrossConnect object for some computation.
    Now I have to create an object of CrossConnect type, add that to nmsArray[] and pass it into private method createRoute(someObj<CrossConnect>[]){}.
    Question is should we populate only those 2 objects in CrossConnect Object which needs to be used in createRoute(..) method, or does it make sense to populate(instatiate them) all the attributes of CrossConnect object with an idea that other attributes apart from those 2 may be used in future. Assuming there is no memory constraint with the application and no time critcality, would it be a good idea to go about instantiating all the attributes of an object irrespective of their usage pattern.

    Regards!!


  2. #2
    Member
    Join Date
    Nov 2011
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Regarding good coding practices

    Quote Originally Posted by shaggarw View Post
    Hi folks,

    I wanted to get your opinion around following situation:-
    I have an object with a name nmsArray<CrossConnect>[] ,array of CrossConnect type object. CrossConnect object has some 15 attributes and corresponding getters and setters.
    This array need to be passed to a private method createRoute(someObj<CrossConnect>[]), which as of now uses only 2 attributes out of 15 of the CrossConnect object for some computation.
    Now I have to create an object of CrossConnect type, add that to nmsArray[] and pass it into private method createRoute(someObj<CrossConnect>[]){}.
    Question is should we populate only those 2 objects in CrossConnect Object which needs to be used in createRoute(..) method, or does it make sense to populate(instatiate them) all the attributes of CrossConnect object with an idea that other attributes apart from those 2 may be used in future. Assuming there is no memory constraint with the application and no time critcality, would it be a good idea to go about instantiating all the attributes of an object irrespective of their usage pattern.

    Regards!!
    Well, the simple rule is that: don't create things which you won't use. Keep it simple! If there are only two attributes are being used across the program, so there is no need to define other attributes that you won't use. If you intend to use the other attributes in future, so do declare them, it won't hurt anyone!

    Spring 3
    Last edited by cafeteria84; January 22nd, 2012 at 03:01 PM.

Similar Threads

  1. which is good GUI designer for eclipse
    By t.mahesmca in forum Java IDEs
    Replies: 2
    Last Post: October 5th, 2011, 07:49 AM
  2. Error Messages Best Practices
    By Dalek_Supreme in forum Java Theory & Questions
    Replies: 0
    Last Post: April 1st, 2011, 07:22 PM
  3. Good morning everyone
    By r-veras in forum Member Introductions
    Replies: 1
    Last Post: January 28th, 2011, 08:36 AM
  4. Good morning!
    By gnome in forum Member Introductions
    Replies: 0
    Last Post: January 1st, 2011, 03:18 PM
  5. Want to write good programs
    By dak2007 in forum Member Introductions
    Replies: 2
    Last Post: April 22nd, 2010, 04:21 PM