-
Notifications
You must be signed in to change notification settings - Fork 103
Lesson 19 and 20 #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: for-pr
Are you sure you want to change the base?
Lesson 19 and 20 #86
Conversation
| new Car(2020, "e555ee55", "red", "skoda") | ||
| }; | ||
|
|
||
| CarService dataBase = new CarService(cars); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
database - это одно слово:) но название некорректно - carService и очевиднее и лучше. Так-то, он не обязан хранить данные - вполне может обращаться внутри себя к другому классу, ответственному за хранение
| hashcode += color == null ? 0 : color.hashCode(); | ||
| hashcode += model == null ? 0 : model.hashCode(); | ||
| } | ||
| return hashcode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нарушен контракт equals-hashcode. Сейчас у одинаковых по икуалз объектов могут быть разные хэшкоды, что недопустимо
| hashcode += color == null ? 0 : color.hashCode(); | ||
| hashcode += model == null ? 0 : model.hashCode(); | ||
| } | ||
| return hashcode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не хватает пустой строки перед return. И поехала табуляция. ctrl+alt+L - автоформатирование кода
| @@ -0,0 +1,18 @@ | |||
| package com.walking.lesson19_object_methods.model; | |||
|
|
|||
| public class CarService { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
сервис - не модель. Обычно сервисы выносят в отдельный пакет
| public class CarService { | ||
| private final Car[] cars; | ||
|
|
||
| public CarService(Car[] allcars) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
переменные, прааметры методов и поля именуются в camelCase. Т.е. здесь - allCars. Впрочем, просто cars было бы достаточно
| this.cars = allcars; | ||
| } | ||
|
|
||
| public Car searchCar(Car userCar) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нет смысла в постфиксе Car. Вполне логично, что метод поиска в CarService ищет объекты типа Car. Т.е. можно назвать метод search. Или, что более распространено - find
| } | ||
| } | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
опционально можно добавить методы добавления, изменения и удаления машины. Это не обязательно по условию, но выглядит логично в контексте работы с подобным приложением
|
|
||
| public class File { | ||
| private String fileName; | ||
| private final FileType fileType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почему я могу менять все, кроме типа файла? Вполне логично заменить, например, txt на sql/properties/другой текстовый формат. В целом, мелкое замечание
| private final FileType fileType; | ||
| private int fileSize; | ||
|
|
||
| public File(String fileName, FileType fileType, int fileSize){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
пробел перед {
| } | ||
|
|
||
| @Override | ||
| public String toString(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
|
|
||
| public File search (String userFile) throws FileNotFoundException { | ||
| for (File file : files) { | ||
| if (userFile.equals(file.getFileName())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в File не переопределен икуалз
| @@ -0,0 +1,7 @@ | |||
| package com.walking.lesson20_exceptions.task1_throwsException.service; | |||
|
|
|||
| public class FileNotFoundException extends Exception{ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не хватает пробела перед {. Логичнее было бы наследоваться от RuntimeException - ты ведь файл ищешь не в файловой системе, а в ин-меморе хранилке - массиве
| if (userFigure == 1) { | ||
| figure = new Square(); | ||
| } else { | ||
| figure = new Triangle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
хватило бы тернарки. Или switch-case, который выглядел бы лучше при потениальном увеличении числа наследников фигуры
| } else { | ||
| figure = new Triangle(); | ||
| } | ||
| System.out.println(figure.buildFigure(userWidth)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
пустая строка перед этой строчкой
| @@ -0,0 +1,22 @@ | |||
| package com.walking.lesson20_exceptions.task2.model; | |||
|
|
|||
| public class Square implements Figure{ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
пробел
| @@ -0,0 +1,7 @@ | |||
| package com.walking.lesson20_exceptions.task2.service; | |||
|
|
|||
| public class InputValidationException extends RuntimeException{ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
пробел
| public class Main { | ||
| public static void main(String[] args) { | ||
| Animal[] animals = {new Cat(), new Dog(), new Cow()}; | ||
| soundAll(animals); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лишний таб.
Lesson 19 is done.
Lesson 20 all tasks done.