[Biojava-l] Access to variables
mark.schreiber at novartis.com
mark.schreiber at novartis.com
Wed May 10 03:54:07 UTC 2006
Further to this I would add that sometimes get / set methods should not be
public. This is usually the case for set methods where you don't want the
possibility of something external to the class or package calling the set
method and messing things up for you. For a set method to only be
accesible internally you would make it private. If you make it protected
you have more options. If you make it public you expose it to the world.
Basically if you think your set method is not safe for general developers
to use under normal circumstances or if it is only relevant to other
classes in your API you should make it protected or private.
Hope that was not too confusing. Bloch's Effective Java is probably much
clearer/
- Mark
Mark Schreiber
Research Investigator (Bioinformatics)
Novartis Institute for Tropical Diseases (NITD)
10 Biopolis Road
#05-01 Chromos
Singapore 138670
www.nitd.novartis.com
phone +65 6722 2973
fax +65 6722 2910
David Huen <smh1008 at cam.ac.uk>
Sent by: biojava-l-bounces at lists.open-bio.org
05/09/2006 09:12 PM
To: n.haigh at sheffield.ac.uk
cc: biojava-l at lists.open-bio.org, (bcc: Mark Schreiber/GP/Novartis)
Subject: Re: [Biojava-l] Access to variables
On May 9 2006, Nathan S. Haigh wrote:
>Apologies if this comes through more than once - I forgot to send in
plain
>text without attachments!
>
>In case you don't know - I'm new to Java?.
>
>I'm working out an interface/class structure for part of an app I want to
>convert from Perl to Java and I have a question about the best way to
>provide access to variables to the client programmer:
>
>Is it best to have variables you want the client programmer to access
just
>made public or is it best to provide access to them via a get/set method?
>> From my limited reading of "Thinking in Java" I would think it best to
>> hide
>the implementation from the user and provide methods to access these
>variables e.g. setThreshold and getThreshold modify the private variable
>threshold - is that correct or am I way off the mark!?
>
Breaking object encapsulation is generally a bad thing in OO programming
so, yes, avoid it when you can. We try to make it difficult to do so in
BioJava anyway :-).
Regards,
David
_______________________________________________
Biojava-l mailing list - Biojava-l at lists.open-bio.org
http://lists.open-bio.org/mailman/listinfo/biojava-l
More information about the Biojava-l
mailing list