里氏替换原则 - 维基百科,自由的百科全书
原则 |
---|
在面向对象的程序设计中,里氏替换原则(Liskov Substitution principle)是对子类型的特别定义。它由芭芭拉·利斯科夫(Barbara Liskov)在1987年在一次会议上名为“数据的抽象与层次”的演说中首先提出。[1]
里氏替换原则的内容可以描述为: “派生类(子类)对象可以在程式中代替其基类(超类)对象。” 以上内容并非利斯科夫的原文,而是译自罗伯特·马丁(Robert Martin)对原文的解读。其原文为:
- Let be a property provable about objects of type . Then should be true for objects of type where is a subtype of .
芭芭拉·利斯科夫与周以真(Jeannette Wing)在1994年发表论文并提出以上的Liskov代換原則。
引用
[编辑]- ^ Liskov, Barbara. Data abstraction and hierarchy. 1987-10-04 [2008-03-23]. (原始内容存档于2019-06-30).
參考文獻
[编辑]一般參考
- Leavens, Gary T.; Dhara, Krishna K. Concepts of Behavioral Subtyping and a Sketch of Their Extension to Component-Bases Systems. Leavens, Gary T.; Sitaraman, Murali (编). Foundations of component-based systems. Cambridge University Press. 2000. ISBN 0-521-77164-1. This paper surveys various notions of behavioral subtyping, including Liskov and Wing's.
- Liskov, B. H.; Wing, J. M. A behavioral notion of subtyping. ACM Trans. Program. Lang. Syst. 16 (6). November 1994: 1811–41. doi:10.1145/197320.197383. 参数
|journal=
与模板{{cite conference}}
不匹配(建议改用{{cite journal}}
或|book-title=
) (帮助)
An updated version appeared: Liskov, Barbara; Wing, Jeannette. Behavioral Subtyping Using Invariants and Constraints (技术报告). Carnegie Mellon University. July 1999 [2022-01-06]. CMU-CS-99-156. (原始内容存档于2012-07-16). The formalization of the principle by its authors. - Plösch, Reinhold. Contracts, scenarios and prototypes: an integrated approach to high quality software. Springer. 2004. ISBN 3-540-43486-0. Contains a gentler introduction to behavioral subtyping in its various forms in chapter 2.
- Martin, Robert C. The Liskov Substitution Principle (PDF). C++ Report. March 1996. (原始内容 (PDF)存档于2015-11-28). An article popular in the object-oriented programming community that gives several examples of LSP violations.
- Majorinc, Kazimir. Ellipse-Circle Dilemma and Inverse Inheritance. ITI 98, Proceedings of the 20th International Conference of Information Technology Interfaces, Pula, 1998. : 627–632. ISSN 1330-1012. OCLC 894960131.
|journal=
被忽略 (帮助) This paper discusses LSP in the mentioned context.
具體參考
- Liskov, B. Keynote address — data abstraction and hierarchy. ACM SIGPLAN Notices. May 1988, 23 (5): 17–34. doi:10.1145/62139.62141. A keynote address in which Liskov first formulated the principle.
- Meyer, B. [[Object-oriented Software Construction|物件導向軟體構建]]. Prentice Hall. 1988. ISBN 0-13-629031-0.
参閲
[编辑]- SOLID - “SOLID”中的 L 指代了里氏替换原则
- 類型簽名
- 參考透明度(Referential transparency)
- 求精法 (編程計算)(Refinement (computing))
- 組合優於繼承(Composition over inheritance)
外部連結
[编辑]- Norvell, T.S. The Liskov Substitution Principle (PDF). 2003 [2022-01-06]. (原始内容 (PDF)存档于2022-01-30).
- Liskov Substitution Principle Explained (页面存档备份,存于互联网档案馆)
- SOLID Class Design: The Liskov Substitution Principle (页面存档备份,存于互联网档案馆)
- LSP: Liskov Substitution Principle (页面存档备份,存于互联网档案馆)