@@ -1235,21 +1235,29 @@ class HttpRequester {
12351235** [ ⬆ 返回顶部] ( #代码整洁的-javascript ) **
12361236
12371237
1238- ### Liskov Substitution Principle (LSP)
1238+ ### 里氏代换原则 (LSP)
12391239This is a scary term for a very simple concept. It's formally defined as "If S
12401240is a subtype of T, then objects of type T may be replaced with objects of type S
12411241(i.e., objects of type S may substitute objects of type T) without altering any
12421242of the desirable properties of that program (correctness, task performed,
12431243etc.)." That's an even scarier definition.
12441244
1245+ 这是针对一个非常简单的里面的一个恐怖意图, 它的正式定义是: “如果 S 是 T 的一个子类型, 那么类
1246+ 型为 T 的对象可以被类型为 S 的对象替换(例如, 类型为 S 的对象可作为类型为 T 的替代品)儿不需
1247+ 要修改目标程序的期望性质 (正确性、 任务执行性等)。” 这甚至是个恐怖的定义。
1248+
12451249The best explanation for this is if you have a parent class and a child class,
12461250then the base class and child class can be used interchangeably without getting
12471251incorrect results. This might still be confusing, so let's take a look at the
12481252classic Square-Rectangle example. Mathematically, a square is a rectangle, but
12491253if you model it using the "is-a" relationship via inheritance, you quickly
12501254get into trouble.
12511255
1252- ** Bad:**
1256+ 最好的解释是, 如果你又一个基类和一个子类, 那个基类和字类可以互换而不会产生不正确的结果。 这可
1257+ 能还有有些疑惑, 让我们来看一下这个经典的正方形与矩形的例子。 从数学上说, 一个正方形是一个矩形,
1258+ 但是你用 "is-a" 的关系用继承来实现, 你将很快遇到麻烦。
1259+
1260+ ** 不好的:**
12531261``` javascript
12541262class Rectangle {
12551263 constructor () {
@@ -1303,7 +1311,7 @@ const rectangles = [new Rectangle(), new Rectangle(), new Square()];
13031311renderLargeRectangles (rectangles);
13041312```
13051313
1306- ** Good ** :
1314+ ** 好的: **
13071315``` javascript
13081316class Shape {
13091317 setColor (color ) {
0 commit comments