From grimoire
Assigns responsibilities so each class stays focused on one related concern. Use when a class is hard to name, does unrelated work, or a change risks breaking unrelated parts.
How this skill is triggered — by the user, by Claude, or both
Slash command
/grimoire:apply-high-cohesionThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Assign responsibilities so that each class remains focused on one strongly related set of concerns that can be understood and explained as a unit.
Assign responsibilities so that each class remains focused on one strongly related set of concerns that can be understood and explained as a unit.
Adopted by: GRASP (Larman, 2004); SOLID SRP (Martin, 2003); Unix philosophy; Go standard library design (small, focused interfaces). High cohesion is a foundational metric in software quality measurement — Chidamber & Kemerer (1994, IEEE TSE) established the Lack of Cohesion of Methods (LCOM) metric, now a standard quality gate in SonarQube, CodeClimate, and NDepend. Impact: Chidamber & Kemerer (1994) showed that LCOM is inversely correlated with fault-proneness — low-cohesion classes have statistically higher defect density. Palomba et al. (2018, IEEE TSE) confirmed that God Classes (the archetypal low-cohesion pattern) have 3–4x higher change frequency than average classes. High-cohesion classes are self-documenting: the class name describes everything inside it. Why best: Low cohesion grows through feature accretion — each new feature lands in the nearest existing class rather than the right class. The result is a God Class that knows everything and changes for every reason. High cohesion is not achieved by refusing to add features; it is achieved by asking "does this feature belong here, or in a focused class I haven't created yet?" The distinction between High Cohesion (GRASP) and SRP (SOLID) is axis: SRP asks "how many actors would cause this to change?"; High Cohesion asks "how related are the operations this class performs?"
Sources: Larman, "Applying UML and Patterns" (Prentice Hall, 2004); Chidamber & Kemerer, "A Metrics Suite for Object-Oriented Design" (IEEE TSE, 1994); Palomba et al., "Revisiting the Impact of Code Smells" (IEEE TSE, 2018)
A highly cohesive class can be named with one noun and a short description. If the name requires "And" or a vague term like "Manager", "Handler", or "Util", it is likely doing too much.
| Name | Signal |
|---|---|
OrderCalculator | Cohesive — one focused operation |
UserManager | Suspicious — "manage" hides multiple concerns |
OrderAndPaymentService | Low cohesion — explicitly two concerns |
Utils | No cohesion — a wastebasket class |
List all instance methods. Draw a line between two methods if they share an instance variable. Disconnected groups signal low cohesion — the class contains multiple independent clusters that belong in separate classes.
# Low cohesion — two disconnected groups: reporting and user management
class UserService:
def find_user(self, id): return self.user_db.find(id) # group A: uses user_db
def update_email(self, id, email): ... # group A: uses user_db
def generate_monthly_report(self): ... # group B: uses report_db
def export_report_csv(self): ... # group B: uses report_db
# A and B never share an instance variable — this is two classes
# High cohesion — split into two focused classes
class UserRepository:
def find(self, id): ...
def update_email(self, id, email): ...
class UserReportGenerator:
def generate_monthly(self): ...
def export_csv(self): ...
When adding a feature, evaluate each candidate class by asking: "does this responsibility relate to the existing operations in that class?"
A God Class is a class that has grown to encompass unrelated responsibilities. Split it by identifying distinct clusters of methods and data, each of which belongs together.
# God Class — OrderSystem does everything
class OrderSystem:
def place_order(self): ... # ordering
def cancel_order(self): ... # ordering
def charge_payment(self): ... # payment
def refund_payment(self): ... # payment
def send_confirmation(self): ... # notification
def send_cancellation(self): ... # notification
def generate_invoice(self): ... # invoicing
# Split into 4 cohesive classes
class OrderManager: # ordering
class PaymentProcessor: # payment
class Notifier: # notification
class InvoiceGenerator: # invoicing
Splitting a class too aggressively raises coupling — each new class needs to know about others. Find the natural split: separate what has different rates of change or different collaborators, not what merely appears in different lines.
A class with 8 cohesive methods serving one concept is better than 4 classes of 2 methods each that all call each other.
Splitting by operation type instead of concept. Moving all "create" methods to one class and all "update" methods to another produces structural cohesion but not conceptual cohesion. Group by domain concept, not by CRUD verb.
Equating cohesion with size. A small class can be incoherent (two unrelated methods). A large class can be highly cohesive (50 methods all serving one complex domain concept, like a geometry engine). Measure by relatedness, not line count.
Confusing High Cohesion with SRP. SRP asks: how many actors need this to change? High Cohesion asks: how related are the responsibilities? Both point at the same smell (bloated classes) but from different angles. Applying both gives the clearest guidance.
npx claudepluginhub jeffreytse/grimoire --plugin grimoireApplies low coupling principle when assigning responsibilities to classes. Detects and reduces excessive dependencies to improve testability and maintainability.
Evaluates class and routine design against Code Complete rules: LSP inheritance, parameter count limits, cohesion classification, containment-vs-inheritance.
SOLID principles (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion) for object-oriented design.