[Bluej-discuss] syntax of method calling (not really)

Stephen Bloch sbloch at adelphi.edu
Tue Jul 11 16:09:53 BST 2006


Chen Li writes:
>    public String do_revComSeq()
>         {
>            String revComSeq= new 
>StringBuilder(do_comSeq()).reverse().toString().toUpperCase();
>             return revComSeq;
>           }

Wouldn't it be simpler to just call do_comSeq on the result of 
do_revSeq, or vice versa?

Oh, no, I see, you've still got both of those methods operating on 
the instance variable "seq" rather than on a parameter, so you can't 
call one on the result of the other.  If you wrote all three methods 
to take in a String parameter and return a String result, you could 
combine them easily:

public String do_revComSeq(String seq)
    {
    return do_revSeq(do_comSeq(seq));
    }

Alternatively, you could have each method return a SeqReader instead 
of a String, and write

public SeqReader do_revComSeq ()
    {
    return this.do_comSeq().do_revSeq();
    }

Either of these approaches would be much more flexible and elegant 
than the current version.

>public class SeqReader

The name of this class still suggests that you're organizing the 
program in terms of verbs like "read" rather than nouns like "genetic 
sequence".  But it is shorter and clearer this way than before.

>    //use print_* methods to print results to the
>terminal to  make sure to get the expected outputs

Again, this isn't really necessary if you're working in BlueJ.  Yes, 
eventually you might want some I/O methods if you have special 
formatting requirements, but that's a low priority.  If base 
sequences need to be formatted in a special way, I would do it by 
writing a toString() method, rather than several different methods 
using System.out.print.

-- 
					Stephen Bloch
					sbloch at adelphi.edu


More information about the bluej-discuss mailing list