HIT软件构造:6.面向可维护性的构造技术

本文探讨了软件可维护性的关键度量指标,包括圈复杂度、代码行数、可维护性指数、继承层次和类耦合度,强调了单元测试覆盖的重要性。此外,详细阐述了SOLID原则,即单一责任原则、开放/封闭原则、Liskov替换原则、接口隔离原则和依赖倒置原则,这些原则有助于构建更稳定、可扩展的系统。同时,正则表达式的应用及其解析器的开发也被提及,作为处理字符串任务的有效工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、可维护性的常见度量指标

二、聚合度与耦合度

三、SOLID

四、正则表达式


一、可维护性的常见度量指标

Cyclomatic Complexity 圈复杂度

Lines of Code 代码行数

Maintainability Index (MI) 可维护性指数

Depth of Inheritance 继承的层次数

Class Coupling 类之间的耦合度 (高聚合,低耦合)

Unit test coverage单元测试的覆盖度

二、聚合度与耦合度

Coupling(耦合度):

Coupling is the measure of dependency between modules. A dependency exists between two modules if a change in one could require a change in the other.

决定:

– The number of interfaces between modules (quantity), and

– Complexity of each interface (determined by the type of communication) (quality)

Cohesion(聚合度):

Cohesion is a measure of how strongly related the functions or responsibilities of a module are.

A module has high cohesion if all of its elements are working towards the same goal.

三、SOLID

1.Single Responsibility Principle(SRP)单一责任原则:

不应该有多于1个原因让你的ADT发生变化,否则就拆分开

2.Open/Closed Principle (OCP)(面向变化的)开放/封闭原则:

3.Liskov Substitution Principle (LSP) Liskov替换原则:

LSP: Subtypes must be substitutable for their base types. (子类型必须能够替换其基类型)

4.Interface Segregation Principle (ISP) 接口隔离原则:

Clients should not be forced to depend upon methods that they do not use. (客户端不应依赖于它们不需要的方法)

5.Dependency Inversion Principle (DIP) 依赖转置原则:

Abstractions should not depend upon details (抽象的模块不应依赖于具体的模块)

Details should depend upon abstractions (具体应依赖于抽象)

四、正则表达式

It is a widely-used tool for many string-processing tasks that need to disassemble a string, extract information from it, or transform it.

根据语法,开发一个它的解析器,用于后续的解析

强制元字符被视为普通字符的两种方法:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值