What1slove / RefactoringLab

Вторая лабораторная по рефакторингу
0 stars 0 forks source link

Одержимость примитивными типами(Missile) #14

Open What1slove opened 4 years ago

What1slove commented 4 years ago

Методы getCoords и getLayerCoords Неуместное использование массивов int когда данные имеют смысл Почему плохо: 1 Очень тяжело читается и понимается 2 Можем забыть какая ячейка массива каким данным соответствует 3 При изменении бизнес-логики придётся всё менять и переписывать Код: public List<int[]> getCoords(Level lev){ int[][] coords = new int[5][3]; Column c = lev.getColumns().get(colnum); int[] p1 = c.getFrontPoint1(); int[] p2 = c.getFrontPoint2(); coords[0][0] = p1[0]+(p2[0] - p1[0])*2/5; coords[0][1] = p1[1]+(p2[1] - p1[1])*2/5; coords[0][2] = zpos-HEIGHT_H; coords[1][0] = p1[0]+(p2[0] - p1[0])/2; coords[1][1] = p1[1]+(p2[1] - p1[1])/2; coords[1][2] = zpos-HEIGHT; coords[2][0] = p1[0]+(p2[0] - p1[0])*3/5; coords[2][1] = p1[1]+(p2[1] - p1[1])*3/5; coords[2][2] = zpos-HEIGHT_H; coords[3][0] = p1[0]+(p2[0] - p1[0])/2; coords[3][1] = p1[1]+(p2[1] - p1[1])/2; coords[3][2] = zpos; coords[4] = coords[0]; return Arrays.asList(coords); } public List<int[]> getLayerCoords(Level lev){ int[][] coords = new int[5][3]; Column c = lev.getColumns().get(colnum); int[] p1 = c.getFrontPoint1(); int[] p2 = c.getFrontPoint2(); coords[0][0] = p1[0]+(p2[0] - p1[0])*9/20; coords[0][1] = p1[1]+(p2[1] - p1[1])*9/20; coords[0][2] = zpos-HEIGHT_H; coords[1][0] = p1[0]+(p2[0] - p1[0])/2; coords[1][1] = p1[1]+(p2[1] - p1[1])/2; coords[1][2] = zpos-HEIGHT*3/5; coords[2][0] = p1[0]+(p2[0] - p1[0])*11/20; coords[2][1] = p1[1]+(p2[1] - p1[1])*11/20; coords[2][2] = zpos-HEIGHT_H; coords[3][0] = p1[0]+(p2[0] - p1[0])/2; coords[3][1] = p1[1]+(p2[1] - p1[1])/2; coords[3][2] = zpos-HEIGHT*2/5; coords[4] = coords[0]; return Arrays.asList(coords); }