아름프로 2003. 8. 2. 13:21

Introduce Assertion


A section of code assumes something about the state of the program.

Make the assumption explicit with an assertion.

        double getExpenseLimit() {
                // should have either expense limit or a primary project
                return (_expenseLimit != NULL_EXPENSE) ?
                        _expenseLimit:
                        _primaryProject.getMemberExpenseLimit();
        }


        double getExpenseLimit() {
                Assert.isTrue (_expenseLimit != NULL_EXPENSE || _primaryProject != null);
                return (_expenseLimit != NULL_EXPENSE) ?
                        _expenseLimit:
                        _primaryProject.getMemberExpenseLimit();
        }

For more information see page 267 of Refactoring



***** 아름다운프로님에 의해서 게시물 복사 + 카테고리변경되었습니다 (2003-12-18 17:27)