¿¹Á¦

public static void main( String[] args) {
if ( args.length > 3 ) {
System.out.println( "More than 3" ); //$NON-NLS-1$
if ( args[ 0 ].startsWith( "a" ) ) { //$NON-NLS-1$
System.out.println( "Starts with a" ); //$NON-NLS-1$
if ( args[ 1 ].endsWith( "z" ) ) { //$NON-NLS-1$
System.out.println( "Ends with z"); //$NON-NLS-1$
}
}
}
}

¼Ö·ç¼Ç
Á¶°ÇÀ» ¹ÝÀü½ÃŰ°í ¸®ÅÏ ¸í·É¹®À» Ãß°¡ÇϽʽÿÀ.
´ÙÀ½ ¼Ö·ç¼Ç¿¡ ´ëÇØ¼­´Â Refactoring(Martin Fowler)¿¡¼­ ¼³¸íÇϰí ÀÖ½À´Ï´Ù.
  1. °¡Àå ¹Ù±ù¿¡ ÀÖ´Â if¹®ÀÇ Á¶°ÇÀ» ¹ÝÀü½ÃŰ½Ê½Ã¿À.
  2. ¸®ÅÏ ¸í·É¹®À» if¹® ¾Æ·¡ Ãß°¡ÇϽʽÿÀ.
  3. ´õ ÁßøµÈ if¹®ÀÌ ¾øÀ» ¶§±îÁö ÀÌ ´Ü°è¸¦ ¹Ýº¹ÇϽʽÿÀ.

public static void main( String[] args) {
if ( args.length <= 3 ) {
return ;
}

System.out.println( "More than 3" ); //$NON-NLS-1$

if ( !args[ 0 ].startsWith( "a" ) ) { //$NON-NLS-1$
return ;
}

System.out.println( "Starts with a" ); //$NON-NLS-1$

if ( args[ 1 ].endsWith( "z" ) ) { //$NON-NLS-1$
System.out.println( "Ends with z" ); //$NON-NLS-1$
}

}