1️⃣ 最低 | 偶然性内聚(Coincidental Cohesion) | 模块内部的各功能毫无关系,随机拼凑 | 一个模块中既有文件读写,又有图像压缩、还处理用户登录 |
2️⃣ | 逻辑性内聚(Logical Cohesion) | 模块中包含一组逻辑上相似但操作不同的功能,由参数决定执行哪一个 | handleEvent(eventType) |
3️⃣ | 时间性内聚(Temporal Cohesion) | 模块中操作在同一时间被执行(如程序启动时) | initAll() : 打开日志、连接数据库、加载配置等 |
4️⃣ | 过程性内聚(Procedural Cohesion) | 模块中操作按特定顺序执行,但彼此可能无明确数据联系 | processRequest() : 解析请求 → 验证 → 返回响应 |
5️⃣ | 通讯性内聚(Communicational Cohesion) | 模块中所有功能操作使用相同的数据结构或文件 | processCustomerData(file) |
6️⃣ | 顺序性内聚(Sequential Cohesion) | 一个操作的输出是下一个操作的输入 | 读取数据 → 过滤数据 → 写入数据库 |
7️⃣ 最高 | 功能性内聚(Functional Cohesion) | 模块完成单一、清晰、定义良好的功能 | calculateInterest(account) |