Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head First Design Patterns - Principle of Least Knowledge

 
Mike Himstead
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm a little bit confused about a specific exercise regarding the "Least Knowledge" design principle. First of all, I do know what the principle means (I think ), what gives me a headache is one of the "Sharpen your pencil" tasks where one is asked to name classes that violate against the above principle. The classes are both called "House". While I understand the first issues (which is more or less the same mentioned in the chapter) the remarks about the second House class at the solutions page (page 272) puzzles me. My impression is that indeed nothing substantial did change, it looks more like "hacking our way around the principle".

Could anyone shed some light on this?
 
Dave Wood
bronco
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Himstead:
Hi,

I'm a little bit confused about a specific exercise regarding the "Least Knowledge" design principle. First of all, I do know what the principle means (I think ), what gives me a headache is one of the "Sharpen your pencil" tasks where one is asked to name classes that violate against the above principle. The classes are both called "House". While I understand the first issues (which is more or less the same mentioned in the chapter) the remarks about the second House class at the solutions page (page 272) puzzles me. My impression is that indeed nothing substantial did change, it looks more like "hacking our way around the principle".

Could anyone shed some light on this?


Mike,

I think you and the authors agree. My interpretation of the comments in the solution is that they are saying "yeah, technically this no longer violates the PoLK (a.k.a. Law of Demeter), but all we really did was hack around the principle." In other words, it's really no better than it was before...just "fixed" on a technicality.

-dave
 
Mike Himstead
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Dave,

thank you for sharing your thoughts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic