> reflection for any reason... is it better to create a getter and a setter
> for myInteger and make it private, or is it acceptable to just leave it
> public and not create any accessors?

Signature
Antti S. Brax Rullalautailu pitää lapset poissa ladulta
http://www.iki.fi/asb/ http://www.cs.helsinki.fi/u/abrax/hlb/
[1385 messages expunged from folder "Spam"]
> sjsobol@JustThe.net wrote in comp.lang.java.programmer:
>
>>reflection for any reason... is it better to create a getter and a setter
>>for myInteger and make it private, or is it acceptable to just leave it
>>public and not create any accessors?
Rather than thinking setter/getter, you should be thinking what are the
operations that the interface of this class need to support. Don't put
the code away from the data. Getters and setters are an indication
(though not definite proof) that something is up with the design.
> It is always better to use accessors. Maintainability and
> consistency are some good reasons.
I'd permit non-private for Data Transfer Objects (DTO). Pretending to
encapsulate such an object is just daft.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Thomas G. Marshall - 03 Aug 2005 21:51 GMT
Thomas Hawtin coughed up:
>> sjsobol@JustThe.net wrote in comp.lang.java.programmer:
>>
[quoted text clipped - 9 lines]
>> It is always better to use accessors. Maintainability and
>> consistency are some good reasons.
Multithreading safety. If the mutation/access of a member ever becomes a
compound operation, you will be creating something that breaks.
Furthermore, there are many things that may require that the value not be
mucked with during its own "atomic" operation. If you provide direct
access, you don't have a way to mutex.
> I'd permit non-private for Data Transfer Objects (DTO). Pretending to
> encapsulate such an object is just daft.
If an object exists to primarily hold data, then I'd have to agree. If an
object has behavior to any significant degree, then mutator/accessor is
preferred.

Signature
Sometimes life just sucks and then you live.
Steve Sobol - 03 Aug 2005 22:41 GMT
> Don't put
> the code away from the data.
I thought separating code from data is a basic OOP principle - or am I
misunderstanding your point?

Signature
Steve Sobol, Professional Geek 888-480-4638 PGP: 0xE3AE35ED
Company website: http://JustThe.net/
Personal blog, resume, portfolio: http://SteveSobol.com/
E: sjsobol@JustThe.net Snail: 22674 Motnocab Road, Apple Valley, CA 92307
Thomas Hawtin - 03 Aug 2005 23:55 GMT
>> Don't put the code away from the data.
>
> I thought separating code from data is a basic OOP principle - or am I
> misunderstanding your point?
Er, no. You have your data in an object all bound up with the methods
that operate upon it.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Virgil Green - 04 Aug 2005 22:36 GMT
>> Don't put
>> the code away from the data.
>
> I thought separating code from data is a basic OOP principle - or am I
> misunderstanding your point?
Procedural code, yes; DML code, no.

Signature
Virgil