TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Law of Demeter: Always Encapsulate

1 pointsby camnoraover 4 years ago

1 comment

jfengelover 4 years ago
The problem is where the Law of Demeter meets YAGNI. Encapsulation is good, and it&#x27;s best to use languages that nudge toward encapsulation. But you can also encapsulate incorrectly, when the domain grows in ways you didn&#x27;t anticipate, and then all of that encapsulation becomes code you have to undo.<p>Programs are most maintainable when you can make the pieces match the natural pieces of the problem domain, and encapsulate accordingly. Doing so is a judgment call, based on your experience with the domain. You always have to come back to domain knowledge to do it correctly. Making decisions based solely on maxims about software qua software will always turn up contradictions like that.