Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links


Using getters & setters internally

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 11-03-2010
Member
 
Join Date: Mar 2010
Posts: 197
Using getters & setters internally

Sponsored Links
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.

Reply With Quote
  #2  
Old 11-03-2010
Member
 
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.
Reply With Quote
  #3  
Old 11-03-2010
Member
 
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.
Reply With Quote
  #4  
Old 11-03-2010
Member
 
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.
Reply With Quote
  #5  
Old 11-03-2010
Member
 
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.
Reply With Quote
  #6  
Old 11-03-2010
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 09:23 AM.