[Biojava-l] Access to variables

Richard Holland richard.holland at ebi.ac.uk
Tue May 9 12:56:30 UTC 2006


hi there.

Get/Set methods with private fields are by far the preferred way of
doing things. This ensures that the object gets to know whenever one of
its variables has changed. 

For example, assume you had a class that represented a sequence, and one
of the methods in that class computed some expensive statistic on that
sequence and stored that statistic in another variable. If the sequence
itself changed then you'd need to recompute the statistic too. Without
get/set, there'd be no way of knowing the sequence had changed, and no
way of knowing when to recompute the statistic.

cheers,
Richard

On Tue, 2006-05-09 at 12:19 +0100, 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!?
> 
> Thanks for any clarification.
> 
> Nath
> 
> ----------------------------------------------------------------------------
> ------
> Dr. Nathan S. Haigh
> Bioinformatics PostDoctoral Research Associate
>  
> Room B2 211                                            Tel: +44 (0)114 22
> 20112
> Department of Animal and Plant Sciences                Mob: +44 (0)7742 533
> 569
> University of Sheffield                                Fax: +44 (0)114 22
> 20002
> Western Bank                                           Web:
> www.bioinf.shef.ac.uk
> Sheffield                                      
> www.petraea.shef.ac.uk
> S10 2TN                                         	
> ----------------------------------------------------------------------------
> ------
> 
> ---
> avast! Antivirus: Outbound message clean.
> Virus Database (VPS): 0615-2, 12/04/2006
> Tested on: 09/05/2006 12:18:14
> avast! - copyright (c) 1988-2006 ALWIL Software.
> http://www.avast.com
> 
> 
> 
>   
> ---
> avast! Antivirus: Outbound message clean.
> Virus Database (VPS): 0615-2, 12/04/2006
> Tested on: 09/05/2006 12:19:29
> avast! - copyright (c) 1988-2006 ALWIL Software.
> http://www.avast.com
> 
> 
> 
> 
> 
> _______________________________________________
> Biojava-l mailing list  -  Biojava-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biojava-l
> 
-- 
Richard Holland (BioMart Team)
EMBL-EBI
Wellcome Trust Genome Campus
Hinxton
Cambridge CB10 1SD
UNITED KINGDOM
Tel: +44-(0)1223-494416




More information about the Biojava-l mailing list