Skip to content

Commit 63893ec

Browse files
committed
Interface Segregation Principle
1 parent 25966b0 commit 63893ec

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

README-zh-CN.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,21 +1379,31 @@ renderLargeShapes(shapes);
13791379
```
13801380
**[⬆ 返回顶部](#代码整洁的-javascript)**
13811381

1382-
### Interface Segregation Principle (ISP)
1382+
### 接口隔离原则 (ISP)
13831383
JavaScript doesn't have interfaces so this principle doesn't apply as strictly
13841384
as others. However, it's important and relevant even with JavaScript's lack of
13851385
type system.
13861386

1387+
JavaScript 没有接口, 所以这个原则不想其它语言那么严格。 不过, 对于 JavaScript 这种缺少类
1388+
型的语言来说, 它依然是重要并且有意义的。
1389+
13871390
ISP states that "Clients should not be forced to depend upon interfaces that
13881391
they do not use." Interfaces are implicit contracts in JavaScript because of
13891392
duck typing.
13901393

1394+
接口隔离原则说的是 “客户端不应该强制依赖他们不需要的接口。” 在 JavaScript 这种弱类型语言中,
1395+
接口是隐式的契约。
1396+
13911397
A good example to look at that demonstrates this principle in JavaScript is for
13921398
classes that require large settings objects. Not requiring clients to setup
13931399
huge amounts of options is beneficial, because most of the time they won't need
13941400
all of the settings. Making them optional helps prevent having a "fat interface".
13951401

1396-
**Bad:**
1402+
在 JavaScript 中能比较好的说明这个原则的是一个类需要一个巨大的配置对象。 不需要客户端去设置大
1403+
量的选项是有益的, 因为多数情况下他们不需要全部的设置。 让它们变成可选的有助于防止出现一个“胖接
1404+
口”。
1405+
1406+
**不好的:**
13971407
```javascript
13981408
class DOMTraverser {
13991409
constructor(settings) {
@@ -1419,7 +1429,7 @@ const $ = new DOMTraverser({
14191429

14201430
```
14211431

1422-
**Good**:
1432+
**好的:**
14231433
```javascript
14241434
class DOMTraverser {
14251435
constructor(settings) {

0 commit comments

Comments
 (0)