Token导航 LogoToken导航TokenDH.com
研究检索external-serviceclawhub未标认证来源可访问clear审计通过

bookforge-big-class-responsibility-extractionBookforge 大类责任提取

Agent Skill

bookforge-big-class-responsibility-extraction 用于查找、检索和筛选相关信息,适合在 OpenClaw 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

28,301

周安装

757

GitHub Stars

公开资料未说明

下载量

4,870
OpenClaw

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

MIT-0

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:bookforge-big-class-responsibility-extraction(Bookforge 大类责任提取)
来源仓库:https://github.com/quochungto/bookforge-big-class-responsibility-extraction
安装命令:
openclaw skills install bookforge-big-class-responsibility-extraction
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 OpenClaw 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

ClawHubOpenClaw
openclaw skills install bookforge-big-class-responsibility-extraction

简介

用于从超大类中识别并提取不合理职责。

  • 应用 Feathers 7 种启发法和特征草图进行分析。
  • 帮助拆分复杂类以改善代码结构。
  • 使用时需提供类名或代码片段。bookforge-big-class-responsibility-extraction 属于研究检索类 Skill,可作为该场景下的辅助能力补充。
  • 建议结合重构计划逐步实施拆分。

SKILL.md

name
big-class-responsibility-extraction
description
Identify and extract responsibilities from an oversized class using Feathers' 7 heuristics + feature sketches. Use whenever a developer faces 'this class is too big', 'god class', 'monster class', '500-line class', 'class with 50+ methods', 'class with too many responsibilities', 'SRP violation', 'hard to test because class does too much', 'team keeps editing same class', 'merge conflicts on one class'. Activates for 'single responsibility', 'extract class', 'class decomposition', 'responsibility split', 'interface segregation', 'class bloat', 'swamp class', 'god object', 'feature sketch', 'class too big'.
version
1.0.0
homepage
https://github.com/bookforge-ai/bookforge-skills/tree/main/books/working-effectively-with-legacy-code/skills/big-class-responsibility-extraction
metadata
{"openclaw":{"emoji":"📚","homepage":"https://github.com/bookforge-ai/bookforge-skills"}}
status
draft
source-books
title
Working Effectively with Legacy Code
authors
["Michael C. Feathers"]
chapters
[20]
domain
software-engineering
tags
[legacy-code, refactoring, software-engineering, code-quality, srp, interface-segregation]
depends-on
execution
tier
2
mode
hybrid
inputs
description
Oversized class source file + optional change history + current change triggering the refactor
tools-required
[Read, Grep]
tools-optional
[Bash, Edit]
mcps-required
[]
environment
Codebase; git log access improves H7 (focus on current work) accuracy.
discovery
goal
Produce a responsibility map and incremental extraction plan for a big class — act only when a change triggers the work.
tasks
audience
roles
[software-engineer, backend-developer, tech-lead]
experience
intermediate-advanced
when_to_use
triggers
prerequisites
why
Before extracting, know the blast radius of proposed changes
not_for
environment
codebase_required
true
codebase_helpful
true
works_offline
true
quality
scores
{with_skill: null, baseline: null, delta: null}
tested_at
null
eval_count
null
assertion_count
13
iterations_needed
null

Big Class Responsibility Extraction

When to Use

Apply this skill when you encounter a class that has become a "swamp" — one that has accumulated so many responsibilities that changing it is slow, risky, and conflict-prone. The immediate trigger signal is any of:

  • The class has 50+ methods or a large number of instance variables
  • Multiple developers are colliding on edits in the same iteration
  • You cannot describe what the class does in a single sentence without using "and"
  • Adding a test requires understanding the entire class
  • Merge conflicts cluster on one file repeatedly

What this skill does NOT do: it does not prescribe a full rewrite schedule. The output is a responsibility map and an incremental extraction plan that you act on only when a change touches a responsibility area.

Context and Input Gathering

Before starting, collect:

  1. Class source path — the full file for the oversized class
  2. Method inventory — a complete list of all methods and their access modifiers (public, private, protected)
  3. Instance variable list — all fields and their types
  4. Current change — the specific ticket, feature, or bug fix that brought you here today
  5. Change history (optional) — git log --follow -p <file> reveals who edits what, and how often multiple responsibilities change together

Process

Step 1: Confirm the Big Class Pattern

Verify the class meets the threshold for this skill. A big class has two or more of:

  • 50+ methods (or 20+ public methods)
  • 10+ instance variables
  • Multiple developers modifying it in the same sprint
  • Inability to write a test for a single method without setting up the entire class
  • Methods that require reading through large blocks of unrelated code to understand

If the class is borderline, check git history: if the same file appears in commits for unrelated features (login, notifications, billing), the bloat is confirmed.

Step 2: Name the Anti-Pattern — Incremental Class Bloat

Before doing any analysis, name what happened. The class became a swamp through Incremental Class Bloat: each new feature added a few lines or a method because "the data I need is already here." No single commit was catastrophic. Thirty small decisions compounded into a structural problem.

Naming this matters because it prevents the team from repeating it. The rule going forward: when you reach for data in an existing class to add new behavior, ask whether that behavior *belongs* to this class or whether it should live in a class that *uses* this class.

Step 3: Apply the 7 Heuristics to Find Responsibility Candidates

Work through each heuristic. Not all will fire — stop when you have enough candidates to drive the current change.

H1 — Group Methods: Write down every method with its access modifier. Look for naming clusters — groups of methods that share a common noun or verb prefix. For example: authenticate(), validateToken(), refreshSession() form one cluster; sendWelcomeEmail(), sendResetEmail() form another. Each distinct cluster is a candidate responsibility.

*Why:* Method names are the developer's primary signal about what a method is for. Clusters that share a purpose usually share a responsibility.

H2 — Look at Hidden Methods: Count the private and protected methods. If there are far more private methods than public ones, a hidden class is trying to emerge. The test: if you made a private method public, would it feel odd on this class? If yes, it belongs on a different class.

*Why:* The RuleParser example (see Examples section) has 2 public methods and many private ones. The private cluster around nextTerm and hasMoreTerms is a TermTokenizer in disguise.

H3 — Look for Decisions That Can Change: Identify hard-coded assumptions — a specific database, a fixed API endpoint, a particular algorithm. These are not just implementation details; they are responsibilities. If the decision could change independently of everything else the class does, it can be extracted.

*Why:* A change to the hard-coded decision would ripple through methods that have no other reason to change together. Extraction creates a seam.

H4 — Look for Internal Relationships (Feature Sketches): Draw a rough diagram — circles for each instance variable, circles for each method. Draw an arrow from each method to every instance variable or other method it reads or modifies. Look for clusters: groups of methods and variables with dense internal connections but few lines crossing to the rest of the diagram.

The connection between clusters — a thin set of lines linking two otherwise independent groups — is a pinch point. The pinch point defines the interface a new class would present.

*Why:* Feature sketches make latent structure visible without requiring you to read all the code. Clusters with pinch points are extractable with low risk.

H5 — The Primary Responsibility Sentence Test: Try to describe the class in one sentence. Each time you add an "and" or "also" clause, you have identified a secondary responsibility. Example: "UserManager handles authentication and stores preferences and sends notifications" — three distinct responsibilities.

*Why:* The Single Responsibility Principle says a class should have one reason to change. Each "and" clause in your sentence is a separate reason to change.

H6 — Scratch Refactoring: If heuristics H1–H5 do not give you clear candidates, do a scratch refactoring. Spend 20–30 minutes extracting classes and methods freely, ignoring test coverage and production risk. The goal is not to produce working code — it is to reveal what structure is latent in the class. Throw away the scratch work; keep the insights.

*Why:* Sometimes the structure is only visible once you start moving things. Scratch refactoring is an exploration tool, not a commitment.

H7 — Focus on the Current Work: Look at the specific change you need to make today. The code you are adding or modifying is in a particular responsibility area. That area — and only that area — is a candidate for extraction right now.

*Why:* The current change is telling you what the software needs to evolve. Recognizing that a new capability represents a separable responsibility is enough to justify extracting it. You do not need to refactor the whole class — only the responsibility the change touches.

Step 4: Build a Feature Sketch for the Top Candidate

For the responsibility cluster that H4 or H7 identified as most relevant to your current change:

  1. List all methods and instance variables on paper or in a text file
  2. For each method, note which instance variables and other methods it reads or writes
  3. Draw arrows: method → variable/method it uses
  4. Circle groups that have dense internal arrows and thin external connections
  5. Identify the pinch point: the crossing lines between the candidate cluster and the rest of the class

The feature sketch does not need to be precise. It is a disposable tool — make it in 10 minutes, use it, discard it.

Step 5: SRP Sentence Test and Two-Level Check

Write the one-sentence description of the class. Then check two levels:

Interface-level SRP: Does the class *appear* to have too many responsibilities based on its public API? If so, consider adding per-client interfaces (Interface Segregation Principle). Clients that only need a subset of the class's behavior can depend on the interface rather than the full class.

Implementation-level SRP: Does the class *actually do* the work, or does it delegate to helper classes? If it already delegates, the violation is only at the interface level — less urgent. If it actually does everything itself, extraction is urgent.

Always address implementation-level SRP first. Introducing delegation is safer and sets the stage for interface-level cleanup later.

Step 6: Produce the Responsibility Map

Summarize findings from H1–H5 into a responsibility map. Format:

Class: <ClassName>
Primary responsibility: <one sentence>

Identified responsibilities:
  R1: <name> — methods: [...], variables: [...]
  R2: <name> — methods: [...], variables: [...]
  R3: <name> — methods: [...], variables: [...]

Pinch points:
  R1 ↔ R2: <method that connects them>
  R2 ↔ R3: <method that connects them>

Current change touches: R<N>

Step 7: Produce the Incremental Extraction Plan

Strategy: Do not schedule a refactoring week. Identify all responsibilities, share the map with the team, then extract on an as-needed basis. When a change touches a responsibility, extract that responsibility at that time.

Tactics for the current change:

  1. Identify the responsibility area the current change touches (from the map)
  2. List all methods and instance variables belonging to that responsibility
  3. If tests exist for those methods, use Extract Class with full delegation. Feathers' safe extraction steps when tests are absent:

a. Separate the target instance variables into a distinct block in the class declaration b. Extract the bodies of target methods to new methods, prefixed MOVING_ c. Verify — by text search, not just compile — that no moved variables are accessed outside the moved methods d. Create the new class; move the MOVING_-prefixed methods and variables into it e. Create an instance of the new class in the old class and delegate f. Remove the MOVING_ prefix from all moved methods

  1. The old class now delegates to the new class for that responsibility — SRP at the implementation level
  2. If client code must also change, that work is deferred until you have tests around those clients

What to defer: All other responsibilities in the map stay in the class for now. The map is a shared record — the team knows the direction, and each change moves one step toward it.

Inputs

InputRequiredSource
Class source fileYesCodebase
Method + variable listYesRead/Grep the source file
Current change descriptionYesTicket, PR, or developer context
Git log for the fileOptionalgit log --follow -p <file>

Outputs

responsibility-map.md — The results of H1–H5 analysis: method clusters, hidden method findings, decision candidates, feature sketch clusters, sentence test result, two-level SRP assessment.

extraction-plan.md — Incremental extraction steps tied to the current change: which responsibility to extract now, which methods and variables move, the safe step-by-step procedure, and what is deferred.

Key Principles

  • Don't binge-refactor. Extract only what the current change requires. The rest of the map informs future changes; it does not mandate immediate action.
  • SRP has two levels. A class can violate SRP at the interface (looks too big) without violating it at the implementation (actually delegates). Always fix implementation-level first.
  • Private-method clusters are hidden classes trying to emerge. Many private methods on a class is a signal, not a coincidence.
  • Feature sketches are disposable. Rough, fast, and thrown away after use. They are not UML diagrams and should not be maintained.
  • The sentence test is the fastest signal. If you need "and" to describe the class, you have found at least two responsibilities in under a minute.
  • Scratch refactoring is exploration, not commitment. Code produced in scratch refactoring is thrown away. Insights from it are kept.
  • The current change is your guide. The change tells you what the software is being asked to do. That is the area to clean up.

Examples

Example 1: RuleParser — Method Grouping Reveals 4 Responsibilities

RuleParser has 2 public methods (evaluate, addVariable) and many private methods (nextTerm, hasMoreTerms, several *Expression methods).

Apply H1 (group methods): the *Expression methods cluster together (evaluation); nextTerm and hasMoreTerms cluster together (tokenization); addVariable stands alone with the variables field (variable management); evaluate anchors parsing.

Apply H2 (hidden methods): the private nextTerm/hasMoreTerms group would not feel odd as public methods — but only on a class called TermTokenizer, not on RuleParser.

Responsibility map: Parsing, Expression evaluation, Term tokenization, Variable management.

Extraction plan: When the next change touches tokenization (e.g., new term syntax), extract TermTokenizer with nextTerm, hasMoreTerms, and the currentPosition field. Delegate from RuleParser. Leave the other responsibilities in place until a change triggers them.


Example 2: UserService — Feature Sketch Reveals 3 Clusters

UserService has 82 methods and 30+ instance variables. Four developers modify it in every sprint and hit merge conflicts weekly.

Apply H4 (feature sketch): draw method-to-variable arrows. Three dense clusters emerge with thin connections between them:

  • Cluster A: authenticate(), validateToken(), refreshSession() + sessionStore, tokenSecret
  • Cluster B: getPreferences(), updatePreferences(), resetPreferences() + preferenceStore, defaultPrefs
  • Cluster C: sendWelcomeEmail(), sendResetEmail(), queueNotification() + emailClient, notificationQueue

Apply H5 (sentence test): "UserService authenticates users and manages preferences and sends notifications" — three clauses, three responsibilities.

Extraction plan for the current sprint's social login feature: The feature touches authentication. Extract AuthenticationService with Cluster A methods and variables. Delegate from UserService. Cluster B and C remain until a change touches them.


Example 3: Change-Triggered Extraction for a Pricing Ticket

A ticket arrives: "Change the pricing calculation to support volume discounts." PricingEngine has 60 methods covering pricing, tax calculation, invoice formatting, and coupon redemption.

Apply H7 (focus on current work): the volume discount change touches the pricing calculation methods. Apply H4 to find the pricing cluster: calculateBasePrice(), applyDiscount(), computeTotal() + priceTable, discountRules.

Extraction plan: Extract PriceCalculator with the pricing cluster. The calculateBasePrice() and applyDiscount() methods become public on PriceCalculator; PricingEngine delegates to it. Add the volume discount logic to PriceCalculator. Tax, formatting, and coupons remain in PricingEngine for now.

This is change-triggered extraction: the ticket forced you to touch pricing, and that is the right time to clean it up.

References

  • Working Effectively with Legacy Code, Michael C. Feathers (2004), Chapter 20: This Class Is Too Big and I Don't Want It to Get Any Bigger
  • Refactoring: Improving the Design of Existing Code, Martin Fowler — Extract Class technique
  • Single Responsibility Principle: Robert C. Martin, Agile Software Development (2002)
  • Interface Segregation Principle: Robert C. Martin

License

CC-BY-SA 4.0 — BookForge Skills contributors. Source book content is copyright Michael C. Feathers / Prentice Hall. This skill distills techniques into executable guidance; it does not reproduce substantial portions of the text.

Related BookForge Skills

Dependencies (run these first):

  • change-effect-analysis — trace the blast radius of a change before extracting
  • dependency-breaking-technique-executor — break dependencies that block extraction

Cross-references (apply alongside):

  • scratch-refactoring-for-code-understanding — the H6 heuristic in standalone form
  • monster-method-decomposition — the method-level analog of this skill
  • dependency-breaking-technique-executor — when extraction is blocked by deep coupling

适合场景

01

OpenClaw 用户查找和安装 Skill 时

02

用户想查找某类 Agent Skill 时

03

需要根据任务场景推荐可安装能力包时

04

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

OpenClaw

74.86%
按下载量换算3,646

安全审计

VirusTotal

通过

ClawScan

通过

Static analysis

通过

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills