convention-law-of-demeter

Detect Law of Demeter violations in object-oriented codebases and enforce direct method calls.

Updated Mar 19, 2026
One-click install
npx skills add https://github.com/sunLeee/optimization --skill convention-law-of-demeter
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: convention-law-of-demeter
Source: https://github.com/sunLeee/optimization/tree/main/.claude/skills/reference/philosophy/laws/demeter
Command: npx skills add https://github.com/sunLeee/optimization --skill convention-law-of-demeter

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Law of Demeter prescribes that an object should talk only to its direct collaborators, preventing chains like a.b.c.d and reducing tight coupling and fragile designs.

Core Features & Use Cases

  • Enforces shallow object interactions to improve maintainability and testability.
  • Reduces knowledge of internal structures by providing simple interfaces or facades.
  • Use Case: refactor deeply nested calls in a service layer to interact with direct dependencies only.

Quick Start

Refactor code to replace chained calls with direct access to the needed collaborators or via a small facade.

Frequently Asked Questions about convention-law-of-demeter

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is the Law of Demeter in object-oriented software design?

The Law of Demeter is a design principle dictating that an object should interact only with its direct collaborators. It prevents deep method call chains like a.b.c.d, reducing tight coupling and improving code maintainability.

How do I refactor deeply nested method chains in my service layer?

To refactor deeply nested method chains, replace chained calls with direct access to needed collaborators or introduce a small facade. This limits knowledge of internal structures and enforces shallow object interactions for better testability.

Why does deep object coupling make my codebase fragile and hard to maintain?

Deep object coupling makes code fragile because changes to internal structures ripple through deep call chains. Limiting interactions to direct collaborators isolates changes, ensuring that modifications do not break unrelated dependent modules.

When should I apply the Law of Demeter during code refactoring?

Apply the Law of Demeter during code refactoring when you identify deep call chains increasing object coupling. Use it to enforce shallow interactions in service layers, ensuring objects communicate only with immediate dependencies.

Can I use facade patterns to fix Law of Demeter violations?

Yes, you can use a small facade to fix Law of Demeter violations. Providing a simple facade interface hides internal structures and reduces deep object coupling by allowing objects to interact with direct dependencies only.

Are there limitations to enforcing strict object coupling rules in clean code?

A limitation of enforcing strict object coupling rules is the potential need to create numerous wrapper or facade methods. This can increase boilerplate code, requiring careful judgment to balance reduced coupling against interface bloat.