引用 SOLID 原则时 "Client" 是什么意思?
What does "Client" mean when referencing SOLID principles?
我目前正在阅读 Adaptive Code: Agile coding with design patterns and SOLID principles 并且在每个原则中他们都引用了 "the client"。 "the client"是谁?
甚至在维基百科中:
https://en.wikipedia.org/wiki/Interface_segregation_principle
在软件工程领域,接口隔离原则 (ISP) 指出不应强迫客户端依赖于它不使用的方法。
谢谢!
此处的客户仅指相关代码构造的用户。因此,假设您编写了一个由数组支持的 Queue
class:
class Queue:
void enqueue(item)
item dequeue()
void resize() // doubles the size of the array if it's full
用户可能是您自己,如果您在其他地方导入自己的 Queue
class,或者如果其他开发人员正在使用您的队列 class,则用户可能是您自己。那么在这种情况下,你的客户端不依赖resize(队列class在内部调用它,所以用户不能调用),接口应该只暴露队列功能需要的东西
interface QueueI:
void enqueue(item)
item dequeue()
我目前正在阅读 Adaptive Code: Agile coding with design patterns and SOLID principles 并且在每个原则中他们都引用了 "the client"。 "the client"是谁?
甚至在维基百科中: https://en.wikipedia.org/wiki/Interface_segregation_principle
在软件工程领域,接口隔离原则 (ISP) 指出不应强迫客户端依赖于它不使用的方法。
谢谢!
此处的客户仅指相关代码构造的用户。因此,假设您编写了一个由数组支持的 Queue
class:
class Queue:
void enqueue(item)
item dequeue()
void resize() // doubles the size of the array if it's full
用户可能是您自己,如果您在其他地方导入自己的 Queue
class,或者如果其他开发人员正在使用您的队列 class,则用户可能是您自己。那么在这种情况下,你的客户端不依赖resize(队列class在内部调用它,所以用户不能调用),接口应该只暴露队列功能需要的东西
interface QueueI:
void enqueue(item)
item dequeue()