<<< Descriptive Names     Index     Maintainability >>>

6. Keeping Scopes Small


  • Data abstraction and hiding closely relates to the scopes of variables and operations.

  • In view of good design we must pursue the goal of localizing attributes and behaviors as much as possible.

  • This greatly improves debugging, testing, documentation, and extensibility of the entire system.

  • Keeping minimal scopes emphasizes good programming style.

  • Consider:

    
    public class Math {
        int temp = 0;
        public int swap( int a, int b ) {
            temp = a;
            a = b;
            b = temp;
            return temp;
        }
    }
    
    
  • Better:

    
    public class Math {
        public int swap( int a, int b ) {
            int temp = 0;
            temp = a;
            a = b;
            b = temp;
            return temp;
        }
    }
    
    
<<< Descriptive Names     Index     Maintainability >>>