Notes on ‘Refactoring ‘ — 4.1 Decompose Conditional

Before Refactor

	   if(age < 60 && age >= 50){
		 salary = age*10 + 100;  
	   }else{
		 salary = age*5;   
	   }

After Refactor

	   if(isMidAge(age)){
		 salary = midAgeSalary(age);  
	   }else{
		 salary = nonMidAgeSalary(age);   
	   }

Benefits: You hightlight the
condiction and make it clear what you are branching on.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.