예제

public static void main( String[] args ) {
if ( args.length > 0 &&
args[ 0 ] != null &&
( args[ 0 ].equals( "input" ) || //$NON-NLS-1$
args[ 0 ].equals( "output" ) || //$NON-NLS-1$
args[ 0 ].equals("verbose") ) ) { //$NON-NLS-1$
System.out.println( "Valid argument" ); //$NON-NLS-1$
}
}

솔루션
관련 절을 메소드로 그룹화하십시오.
  1. 관련 절을 식별하십시오.
  2. 서로 인접한 관련 절을 이동하십시오.
  3. 각 절 그룹을 설명하는 이름이 있는 메소드를 작성하십시오.
  4. 관련 절을 모두 사용할 때까지 이러한 단계를 반복하십시오.

public static void main( String[] args ) {
if ( hasFirstArgument( args ) &&
isValidArgument( args[ 0 ] ) ) {
System.out.println( "Not valid argument" ); //$NON-NLS-1$
}
}

private static boolean hasFirstArgument( String[] args ) {
return ( args.length > 0 ) && ( args[ 0 ] != null );
}

private static boolean isValidArgument( String s ) {
return s.equals( "input" ) || //$NON-NLS-1$
s.equals( "output" ) || //$NON-NLS-1$
s.equals( "verbose" ); //$NON-NLS-1$
}