I was reading this page and came across this sentence in the accepted answer:
I don't like
A
directly knowing aboutB
. But that's a DIP thing not a POJO thing.
What if you can't abstract out B
so that A
isn't aware of it?
Suppose if I have the following Book
class:
public final class Book {
private final Author author;
// constructor and methods left out :D.
}
public final Author {
private final String firstName;
private final String lastName;
// constructor and methods left out :D.
}
I'm aware of the fact that a book might have a list of authors, so it would be better if it was List<Author> authors
, but I want to focus on a specific part of the above code sample.
Some might point out that the Book
class knows about the Author
object.
I don't see why Author
would be an interface
or abstract
class.
Question:
Would you abstract out Author
? If so, how?