Jordi van Selm wrote:I make a 2D-array of the alphabet + the value of the letters and compare that to the char array (1D)...
Is there anyone willing to say which things I need to study?
Emily Rosemond wrote:This reason why I'm guessing is because a setter doesn't return anything, it sets a value. If it were to return something then it probably violates POLA, because clients didn't expect a setter to behave this way and I don't have authority to say it does violate POLA, I don't really know.
Emily Rosemond wrote:You might be able to, because you have years of experience, so you'll be able to look at the code and know, for beginners, it will take time.
Emily Rosemond wrote:This code isn't meant for a program sitting in a publishing company or to interact with a sophisticated database. It's to illustrate my problem, Are there situations where it doesn't makes sense to follow DIP? Book and Author were the only example I could come up with. Why should a specific type of Author exist? Why should a sciencefictionauthor subclass exist? Why can't it be a label applied to an Author?
Paul Clapham wrote:... these days I find it hard to learn things by discussing theories. I find it much more useful to look at actual real-life examples (or reasonable approximations) and understand how they illustrate the theories (or how they conflict with them).
Emily Rosemond wrote:When a class is an attribute of another class, does it always make sense to follow DIP? Are there situations where following DIP will introduce more problems than it solves?
Emily Rosemond wrote:A common pattern is to abstract out the class behind an interface, but what happens if doing so is unnecessary or pointless.
Campbell Ritchie wrote:I think I would prefer the book to have a List of authors. If you have a book like Gamma Helm Johnson and Vlissides, with four authors, which author would hold the List? And I wouldn't want such a List as a static field of Author, so it probably belongs to the book.
Paul Clapham wrote:. . . more than one Author. A design could implement that by having Book have a List of Authors, or you could force Author to take care of the list possibility. . . .
An Author might also have a List<Book> showing their oeuvre. But that latter is making things too complicated, maybe.
Emily Rosemond wrote:Given the requirements, my question still remains, and it's a simple yes or no. Author is an attribute of the Book class, does it make sense to abstract it out?
Emily Rosemond wrote:I wanted to keep the Author immutable
... but if on some rare occasion, an attribute needed to change, I would need to create a whole new object reflecting that change.
The situation has provided a cue; this cue has given the expert access to information stored in memory, and the information provides the answer. Intuition is nothing more and nothing less than recognition. —Herbert Simon
My guess is it will violate the POLA.
Paul Clapham wrote:I'd consider statements like "Book shouldn't know about Author" to be pontificating -- in other words I'm more practical than theoretical these days.