帮助开发者保持类接口抽象一致,避免混杂序列化、持久化等无关职责。
该技能材料表现为纯提示/设计原则文档,无需密钥、未声明远程端点,也未体现代码执行或数据访问能力。结合其开源 GitHub 来源,整体属低风险,但仓库社区采用度与维护状态信息有限,供应链可信度仍需基本核验。
材料明确标注无需密钥或环境变量;作为纯提示型技能,未见请求、存储或传输凭证的设计,凭证泄露面很低。
未声明任何远程端点,且内容仅为类设计抽象原则说明;未见将用户数据外发到第三方服务的迹象。
系统检查项已标注为 prompt-only,README 也呈现为说明文档与示例代码,而非可执行工具规范;未见本机起进程、执行命令或调用系统能力的描述。
材料未声明读取、写入或修改本地文件、数据库、剪贴板或其他资源的能力;从描述看仅提供编程设计建议,不涉及数据权限。
来源为 GitHub 开源仓库,具备可审计性,这是明显的降风险因素;但许可证未声明、0 star、维护状态未知,社区验证和持续维护信号较弱,建议在纳入生产前自行复核仓库内容与变更历史。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "Maintaining Consistent Abstractions" 技能: 1. 下载 https://raw.githubusercontent.com/obra/clank/main/skills/architecture/maintaining-consistent-abstractions/SKILL.md 2. 保存为 ~/.claude/skills/maintaining-consistent-abstractions/SKILL.md 3. 装好后重载技能,告诉我可以用了
请检查下面这段面向对象代码,判断类的接口是否保持了单一且一致的抽象层级,并指出哪些方法混入了序列化、数据库持久化或其他无关职责。请给出重构建议和修改后的示例代码。
输出包含问题定位、职责拆分建议,以及更一致的重构代码示例。
我有一个订单类,既处理业务规则,又直接负责 toJson、saveToDb、loadFromDb。请基于“保持一致抽象”的原则,设计一个更清晰的结构,说明哪些职责应保留在订单类中,哪些应拆分到其他组件。
给出按职责划分后的类设计,并解释领域逻辑与基础设施逻辑的边界。
请为团队编写一份代码评审清单,主题是“保持一致的抽象”。重点覆盖类接口设计、方法命名、职责边界,以及如何识别把业务逻辑和序列化、存储、传输逻辑混在一起的问题。
输出一份可执行的评审清单,帮助团队统一识别和修复抽象层级混乱的问题。
A class interface should present ONE cohesive abstraction. All methods should work toward a consistent purpose at a consistent level.
Core principle: Each class implements one Abstract Data Type (ADT). If you can't identify what ADT the class implements, it has poor abstraction.
Goal: Anyone using the class should see a clear, consistent set of related operations, not a miscellaneous grab-bag.
Apply when designing any class:
Warning signs of poor abstraction:
Baseline violation:
class Employee:
def calculate_annual_salary(self): # ✅ Domain operation
return self.salary * 12
def update_department(self, dept): # ✅ Domain operation
self.department = dept
def to_json(self): # ❌ Serialization detail
return json.dumps({...})
def get_details(self): # ✅ Domain operation
return {...}
Problem: Employee is a domain concept. JSON is a serialization format. Mixing these means:
✅ Separate concerns:
class Employee:
"""Domain: Employee business logic only."""
def __init__(self, name, employee_id, department, salary):
self.name = name
self.employee_id = employee_id
self.department = department
self.salary = salary
def calculate_annual_salary(self): # Domain
return self.salary * 12
def update_department(self, dept): # Domain
self.department = dept
# Separate serializer
class EmployeeSerializer:
"""Concern: Serialization formats."""
@staticmethod
def to_json(employee: Employee) -> str:
return json.dumps({
'name': employee.name,
'id': employee.employee_id,
...
})
@staticmethod
def to_xml(employee: Employee) -> str:
# Can add XML without touching Employee
pass
Now: Employee knows nothing about formats. Add CSV/XML/Protobuf without changing Employee.
Baseline violation:
class Program:
"""Initialize application components."""
def _init_database(self): # Database concern
pass
def _setup_web_server(self): # Web concern
pass
def _start_background_jobs(self): # Jobs concern
pass
def _init_command_stack(self): # Command concern
pass
def _init_report_formatter(self): # Reports concern
pass
Problem: These are unrelated functions grouped because they happen at startup (temporal cohesion). The class has no consistent abstraction - it's a miscellaneous collection.
Code Complete specifically calls this out as poor abstraction.
✅ Each subsystem initializes itself:
class DatabaseSystem:
"""Abstraction: Database operations."""
def initialize(self):
# Database-specific initialization
pass
class WebServer:
"""Abstraction: Web serving."""
def start(self):
# Web server initialization
pass
class BackgroundJobManager:
"""Abstraction: Job processing."""
def start(self):
# Job system initialization
pass
# Coordinator stays high-level
…
先用伪代码梳理方案与迭代思路,再高效转成可执行代码。
帮助用户检索过往 Claude Code 对话,快速找回事实、决策与上下文线索。
帮助用户用接口封装实现细节,从业务层面设计与理解系统
为工程师生成分步实施计划,帮助在陌生代码库中快速落地任务。
用测试驱动方式编写流程文档,先验证再成稿,提升技能说明的可靠性。
帮助你在实施前先比较2到3种方案,选出更优设计与执行路径。
帮助你识别职责混杂的例程,并拆分为单一职责的清晰结构。
帮助开发者识别并避免常见测试反模式,提升单元测试可维护性与可靠性。
帮助开发者按业务领域为代码命名,提升可读性与协作一致性。
帮助开发者用单一职责变量提升代码可读性、可维护性与调试效率
帮助开发者设计、实现并重构六边形架构系统,确保边界清晰且易于测试。
帮助你从间距、字体、阴影与交互细节入手,系统提升界面精致感。