大泥球(Big Ball of Mud)
// 新架构示例
@DomainService
public class OrderService {
private final PaymentGateway paymentGateway;
private final ShippingAdapter shippingAdapter;
}
黄金锤(Golden Hammer)
# 消息中间件抽象层
class MessageBroker(ABC):
@abstractmethod
def publish(self, topic, message): pass
class KafkaBroker(MessageBroker): ...
class RedisBroker(MessageBroker): ...
魔法数字/字符串(Magic Numbers/Strings)
if (status === 5) { // 5代表退款成功?
sendEmail('[email protected]')
}
enum RefundStatus {
SUCCESS = 5,
FAILED = 6
}
const config = {
NOTIFICATION_EMAIL: process.env.EMAIL_ADDR
}
霰弹式修改(Shotgun Surgery)
public interface IPasswordPolicy
{
bool IsSatisfiedBy(string password);
}
public class DefaultPasswordPolicy : IPasswordPolicy
{
public bool IsSatisfiedBy(string password)
{
return password.Length >= 8
&& Regex.IsMatch(password, @"\d+");
}
}
分析瘫痪(Analysis Paralysis)
决策时间盒规则:
1. 每个议题讨论≤15分钟
2. 采用"赞成/反对/弃权"快速表决
3. 设置决策停车位(Parking Lot)
消防演习(Fire Drill)
# CI/CD 流水线示例
stages:
- code_scan:
tools: [sonarqube, semgrep]
- test:
min_coverage: 80%
- deploy:
rollout: canary(10%)
神对象(God Object)
UserManager
类处理认证、授权、日志、缓存// 拆分后结构
@Service
class AuthService { /* 认证逻辑 */ }
@Component
class UserEventLogger { /* 日志处理 */ }
@Repository
class UserCache { /* 缓存管理 */ }
循环依赖(Circular Dependency)
# module_a.py
from module_b import B
class A:
def call_b(self): B().process()
# module_b.py
from module_a import A
class B:
def process(self): A().validate()
// 通过接口解耦
interface IProcessor {
execute(): void;
}
class A implements IProcessor {
constructor(private mediator: Mediator) {}
execute() { this.mediator.handle('B'); }
}
测试后丢弃(Throwaway Testing)
# 行为驱动测试示例
Feature: Payment processing
Scenario: Successful credit card payment
Given a valid credit card
When processing payment for $100
Then should return transaction ID
空对象滥用(Null Object Abuse)
public class NullLogger : ILogger
{
public void Log(string message)
{
// 空实现导致错误静默
}
}
public Optional<ILogger> getLogger() {
return enabled ? Optional.of(fileLogger)
: Optional.empty();
}
静态分析
架构评估
代码规范
质量门禁
# CI 质量门禁示例
if [ "$TEST_COVERAGE" -lt 80 ]; then
echo "覆盖率不足80%"
exit 1
fi
风险级别 | 反模式 | 紧急行动 |
---|---|---|
高危 | 大泥球架构 | 启动架构重构Sprint |
中危 | 循环依赖 | 引入DIP原则解耦 |
低危 | 魔法数字 | 常量提取+配置中心化 |
本手册可作为团队Code Review检查清单,建议结合《重构》《实现模式》等经典著作深入研读。需要任何部分的扩展说明或具体行业场景适配建议,请随时告知。