Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > why use getters/setters?

Thread Tools

why use getters/setters?

Patrick May
Posts: n/a
"M. Ranganathan (NIST)" <(E-Mail Removed)> writes:
> On Sep 8, 9:10 pm, Patrick May <(E-Mail Removed)> wrote:
>> "buu" <(E-Mail Removed)> writes:
>> > can anyone tell me or give me some link?

>> > I'm newbie in java, and get used to work in .net, and getters/setters
>> > confuse me a little bit.

>> Getters and setters are simply a way to control and monitor
>> access to the internal state of an object. They tend to be overused
>> by many Java programmers. I recommend that you read Joshua Bloch's
>> "Effective Java" and take his advice to prefer immutable objects
>> wherever possible.

> Another use case for getters and setters:
> Following the get/set pattern allows tools to use introspection to
> generate code to get/set properties.

[ Please don't top post. ]

Relying on a convention to achieve appropriate results from
introspection is unreliable and unnecessary. The introspection
mechanism can look at the member variables and constructors without
those clues.

The problem with making accessors and mutators available for
introspection is that they are then also available, and will be used
by, other programmers.



S P Engineering, Inc. | Large scale, mission-critical, distributed OO
| systems design and implementation. Removed) | (C++, Java, Common Lisp, Jini, middleware, SOA)
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Cisco 2611 and Cisco 1721 : Why , why , why ????? Cisco 10 05-01-2005 08:49 AM
Why, why, why??? =?Utf-8?B?VGltOjouLg==?= ASP .Net 6 01-27-2005 03:35 PM
Why Why Why You HAVE NO IDEA MCSE 31 04-24-2004 06:40 PM