type
status
date
slug
summary
tags
category
icon
password
Property
Sep 1, 2023 12:51 PM
本节内容
接口与单元测试
- 接口的产生:自底向上(重构),自顶向下(设计)
- C#中接口的实现(隐式,显示,多接口)
- 语言堆面向对象设计的内建支持:依赖反转,接口隔离,开闭原则。。。

抽象类中的抽象方法要求不是private
接口的方法是public的
接口的本质:服务的调用者(服务的消费者)与服务的提供者之前的契约。接口即契约
接口
不使用interface
更换传入参数的类型为IEnumerable
依赖与耦合
引入接口可以降低耦合度
依赖反转
自顶向下逐步求精

依赖反转平衡自顶向下逐步求精这种思维方式。

第一种写法
换为interface的形式
单元测试
还可以用Moq辅助测试

- 作者:Kitety
- 链接:https://www.kitety.com/article/C-sharp-leraning-interfaces-%20dependencies-unit-testing
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。
相关文章