Results 1 to 6 of 6

Thread: Using getters & setters internally

  1. #1
    Join Date
    Mar 2010
    Posts
    197

    Using getters & setters internally

    Hello
    I tried to use the getters & setters in the interior of the same class. But I do not understand why it is not working for my program. If you have any idea then please let me know I am the interested one. Also if you can explain me more details regarding the same then it would be great.

  2. #2
    Join Date
    Nov 2009
    Posts
    347

    Re: Using getters & setters internally

    Hello,
    I do not know if it is really part of "good coding practices," but I support you in your approach. I used to do the same.I find it more secure. I always attribute to "private", and I entered only through accessors. In development, I think this has a big advantage: Eclipse, simply do a "call hierarchy" on the accessors to know what method reads or writes the attribute in question. When a problem of inconsistency on this attribute, it identifies and much easier that may be responsible.

  3. #3
    Join Date
    Nov 2009
    Posts
    356

    Re: Using getters & setters internally

    Hello,
    It is rather a good practice, so if your setter checks the integrity of the variable instance, this will be done both internally and externally and in case of change of this audit you did was make that a single location. If you need more information on this topic then you can visit the sun's official site and then there you can find more detailed help on the same.

  4. #4
    Join Date
    Nov 2009
    Posts
    343

    Re: Using getters & setters internally

    Hello,
    I completely agree with the above post. It is true that it "adds" a little code, but not that much. And it really helps to centralize the validation rules or event management or other things that you do not need immediately but the need may arise later. I hope you are understanding the things here.

  5. #5
    Join Date
    Nov 2009
    Posts
    518

    Re: Using getters & setters internally

    Hello,
    It's just like it if you need to change the assignment, you just do it once. By cons, be careful if you do not end objects, the get and set methods can be redefined in subclasses. Beware still recursive calls, one accessor uses a method that itself uses the accessor in question, and we are left with a stack overflow.

  6. #6
    Join Date
    Nov 2009
    Posts
    347

    Re: Using getters & setters internally

    Hello,
    There is also possibility of edge effects boring if the getters / setters called them. I had a case of mutually exclusive attributes one another, like if one is present one should be null and vice versa. If you do that in each of the setters bah you find yourself with a beautiful infinite recursion as long as you not test if the argument of the setter is null or not. But basically it's always better to use the get / set if they exist.

Similar Threads

  1. VPN is working internally but not externally?
    By Jalela in forum Networking & Security
    Replies: 6
    Last Post: 20-06-2011, 10:41 PM
  2. OWA not working on SBS 2008 internally and externally
    By thematrix in forum Small Business Server
    Replies: 12
    Last Post: 28-04-2011, 03:00 AM
  3. Want to connect a 2.5 SATA disk to a Desktop PC internally
    By Mr.Gogo in forum Hardware Peripherals
    Replies: 5
    Last Post: 10-04-2011, 07:26 PM
  4. IPtables router specific IP internally to another internal IP
    By Illinois in forum Networking & Security
    Replies: 6
    Last Post: 12-05-2010, 09:40 AM
  5. Manage properties of access internally
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 17-02-2010, 03:17 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,924,230.73099 seconds with 16 queries