What metrics can you use to measure SOLID compliance?
Answer
Several code metrics correlate with SOLID compliance: (1) LCOM (Lack of Cohesion in Methods) — measures SRP compliance; high LCOM indicates methods that don't share instance variables, suggesting a class has multiple responsibilities. (2) Afferent/Efferent Coupling (Ca/Ce) and Instability — measures DIP compliance; core modules should be stable (high Ca, low Ce); frameworks should be instable (high Ce). (3) Abstractness — ratio of abstract types to all types; combined with instability gives the Distance from Main Sequence metric. (4) Number of Methods per Interface — high counts suggest ISP violations. (5) Number of Direct Concrete Dependencies — high counts suggest DIP violations. Tools like JDepend (Java), NDepend (.NET), PHPMetrics (PHP), and SonarQube measure these. But metrics are proxies — human code review remains essential for true SOLID assessment.
Previous
How do SOLID principles apply to event-driven architectures?
Next
How do SOLID principles evolve in a growing codebase?
More SOLID Principles Questions
View all →- Advanced How do SOLID principles apply to domain-driven design?
- Advanced How do you balance SOLID principles with pragmatic software development?
- Advanced How does the Hexagonal Architecture (Ports and Adapters) apply DIP?
- Advanced What is the relationship between SOLID and Clean Architecture?
- Advanced How does LSP interact with covariance and contravariance in type systems?