[Biojava-l] Access to variables
Nathan S. Haigh
n.haigh at sheffield.ac.uk
Tue May 9 13:09:58 UTC 2006
Well, I've jumped straight in and am already planning to use get/set methods
for most of my variables :o)
In my app I plan to have a multiple alignment displayed and the user opts to
calculate a consensus sequence as part of a larger process. The user will
also be able to make changes to the alignment. Therefore, if a consensus
sequence has already been calculated I'd like this to be automatically
updated to reflect the changes in the alignment. Do you know of a small
coded example of how this is done i.e. in your example: detecting if the
sequence changed and processing a block of code if it has.
Cheers
Nath
> -----Original Message-----
> From: Richard Holland [mailto:richard.holland at ebi.ac.uk]
> Sent: 09 May 2006 13:57
> To: n.haigh at sheffield.ac.uk
> Cc: biojava-l at lists.open-bio.org
> Subject: Re: [Biojava-l] Access to variables
>
> 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
---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0615-2, 12/04/2006
Tested on: 09/05/2006 14:09:48
avast! - copyright (c) 1988-2006 ALWIL Software.
http://www.avast.com
More information about the Biojava-l
mailing list