3 ms·
Abstraction is necessary, but I think OOP as practiced in many companies likes abstraction a bit too much. At the extreme people treat everything except the co
by ajuc 5y ago
Abstraction is necessary, but I think OOP as practiced in many companies likes abstraction a bit too much.
At the extreme people treat everything except the code they currently work on as black boxes and code like this is written:
//this was written long ago in one class
List<Book> getBooks(BookRepository bookRepository, String author) {
var books = bookRepository.getBooksByAuthor(author);
if (books.isEmpty()) return null;
return books;
}
//this too but in a different task and in a different class
Collection<Book> getBookAboutKeyword(String author, String keyword) {
var books = getBooks(this.bookRepo, author);
if (books == null) {
return null;
}
// let's ignore the fact this should use filtering on db
return books.stream().filter(Book b -> b.about(keyword)).collect(Collections::toList());
}
//this is written now and there's a NPE
List<Book> getBooksAndFooBarThem(List<Books> books, String author, String keyword) {
var books = getBookAboutKeyword(books, author, keyword);
//foobar them
return books;
}
And of course the solution to NPE was to put ANOTHER null check in the getBooksAndFooBarThem function because anything up or down the callstack is black magic.