static void Main() { // First "if statement" refactored Potato potato = new Patato(); //... if (potato != null) { if (!potato.isRotten && potato.isPeeled) { Cook(potato); } } // Second "if statement" refactored const int MIN_ROW = 10; const int MAX_ROW = 20; const int MIN_COL = 10; const int MAX_COL = 20; int currentRow = 12; int currentCol = 15; bool isRowInRange = IsInRange(currentRow, MIN_ROW, MAX_ROW); bool isColInRange = IsInRange(currentCol, MIN_COL, MAX_COL); bool[,] isVisited = new bool[MAX_ROW, MAX_COL]; if (isRowInRange && isColInRange && !isVisited[currentRow, currentCol]) { VisitCell(currentRow, currentCol); isVisited[currentRow, currentCol] = true; } }
static void Main(string[] args) { //if statement one Potato potato = new Patato(); bool isPatatoGoodForCook = !potato.HasNotBeenPeeled && !potato.IsRotten; if (potato != null && isPatatoGoodForCook) { Cook(potato); } //if statement two bool isXInTheRange = x >= MIN_X && x =< MAX_X; bool isYInTheRange = y >= MIN_Y && y =< MAX_Y; bool isCellGoodForVisit = !shouldNotVisitCell; if (isXInTheRange && isYInTheRange && isCellGoodForVisit) { VisitCell(); } }
static void Main(string[] args) { IVegetable carrot = new Carrot(); IVegetable patato = new Patato(); IVegetable paper = new Paper(); IVegetable vegetables = new Vegetables(); IAppearance bowl = new Bowl(); IAppearance steamer = new Steamer(); Chef chef = new Chef(); chef.Wash(); chef.Cut(); chef.Prepare(bowl); chef.Cook(steamer); chef.Serve(); }
static void Main(string[] args) { //if statement one Potato potato = new Patato(); bool isPatatoGoodForCook = !potato.HasNotBeenPeeled && !potato.IsRotten; if (potato != null && isPatatoGoodForCook) { Cook(potato); } //if statement two bool isXInTheRange = x >= MIN_X && x = < MAX_X; bool isYInTheRange = y >= MIN_Y && y = < MAX_Y; bool isCellGoodForVisit = !shouldNotVisitCell; if (isXInTheRange && isYInTheRange && isCellGoodForVisit) { VisitCell(); } }