Добавил всё#68
Добавил всё#68rurm wants to merge 2 commits intojava-online-course:masterjava-online-course/java-oop-template:masterfrom
Conversation
| private String country; | ||
|
|
||
| public Author() { | ||
| super(); |
There was a problem hiding this comment.
А зачем здесь явно дергать super?
| } | ||
|
|
||
| public String getName() { | ||
| return name; |
There was a problem hiding this comment.
Есть правило, что при обращении к полям класса нужно использовать this.. Да, в данном случае нет локальной переменной в методе с похожим именем, как в методе setName. Но желательно и в таких случаях использовать this., чтобы довести это правило до автоматизма (это как с включением сигнала поворота даже когда ты один на пустынной дороге).
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; |
There was a problem hiding this comment.
this.getClass() - обращаешься к методу текущего объекта.
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| Author author = (Author) o; | ||
| return name.equals(author.name) && Objects.equals(lastName, author.lastName) && birthdate.equals(author.birthdate) && country.equals(author.country); |
There was a problem hiding this comment.
Также, необходимо использовать this, а также не писать слишком длинные строки.
Ну и ко всему прочему и name, и birthdate, и country у тебя могут быть null, поэтому лучше их сравнивать также используя Objects.
Можно написать например так:
Objects.equals(this.name, author.name)
&& Objects.equals(this.lastName, author.lastName)
&& Objects.equals(this.birthdate, author.birthdate)
&& Objects.equals(this.country, author.country) ;
| @@ -19,5 +19,64 @@ | ||
| * 6) Переопределить метод toString с выводом всех полей (не забывайте alt+inset) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| private String name; | ||
|
|
||
| public Book() { | ||
| super(); |
There was a problem hiding this comment.
Также явный вызов super() здесь лишний.
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Book{" + |
There was a problem hiding this comment.
Советую использовать String.format, чтобы удобнее и красивее оформить этот код. Почитай как его использовать
There was a problem hiding this comment.
Ну и также местами отсутствует this. при обращении к полям и метода текущего объекта.
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| Book book = (Book) o; | ||
| return numberOfPages == book.numberOfPages && name.equals(book.name); |
There was a problem hiding this comment.
Смотри коммент к такому же методу в классе Author
| super(); | ||
| } | ||
|
|
||
| public SchoolBook(String authorName, String authorLastName, LocalDate publishDate) { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
|
||
| public class SimpleSchoolBookRepository implements BookRepository<SchoolBook> { | ||
| private SchoolBook[] schoolBooks = new SchoolBook[0]; | ||
| private int numOfBooks = 0; |
There was a problem hiding this comment.
У тебя же есть массив schoolBooks, у него есть свойство length. Зачем еще отдельное свойство numOfBooks ?
|
|
||
| @Override | ||
| public int count() { | ||
| return this.numOfBooks; |
There was a problem hiding this comment.
Вот здесь нужно this.schoolBooks.length возвращать, как и в предыдущем репозитории авторов.
|
|
||
| public class SimpleAuthorService implements AuthorService | ||
| { | ||
| AuthorRepository authorRepository; |
There was a problem hiding this comment.
Модификатор где? Обычно, такие свойства как репозитории не должны быть доступны извне сервиса. Поэтому указывают модификатор private
| AuthorRepository authorRepository; | ||
|
|
||
| public SimpleAuthorService() { | ||
| super(); |
There was a problem hiding this comment.
Я бы здесь не использовал конструктор по умолчанию. Если создать сервис с помощью этого конструктора и попытаться сохранить автора, что произойдет?
| public Author findAuthorByBookName(String name) { | ||
| SchoolBook[] books = schoolBookBookRepository.findByName(name); | ||
| if (books.length > 0) | ||
| return authorService.findByFullName(books[0].getAuthorName(), books[0].getAuthorLastName()); |
There was a problem hiding this comment.
А если книг нашлось больше, чем одна?)
Все тесты прошли успешно