Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Roedy Green Newsgroups: comp.lang.java.programmer Subject: Re: Getters and Setters Date: Tue, 09 Aug 2011 21:50:59 -0700 Organization: Canadian Mind Products Lines: 20 Message-ID: <5c3447t4cta8ee9n2dp931r57908a6ocl8@4ax.com> References: <79c811c0-8eec-4c87-8027-2bc971818278@l9g2000prd.googlegroups.com> Reply-To: Roedy Green NNTP-Posting-Host: RCd/Ul4tyxGUBII8WGwa5g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Forte Agent 6.00/32.1186 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6950 On Tue, 9 Aug 2011 18:59:47 -0700 (PDT), Vikram wrote, quoted or indirectly quoted someone who said : >Why do we use getter and setters if we can do the same work by >declaring the public data members. it makes it possible to add code to the setter to for example validate the data. You can add debug code to a getter. In some languages, you can use the clean public variable syntax to access a getter or setter in an expression, so the distinction is blurred. I think Java missed the boat with its incredibly clumsy getter/setter syntax. It is almost like writing assembler. -- Roedy Green Canadian Mind Products http://mindprod.com Most of computer code is for telling the computer what do if some very particular thing goes wrong.