里氏替换原则
在面向对象的程序设计中,里氏替换原则(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 .
引用
- Liskov, Barbara. . 1987-10-04 [2008-03-23]. (原始内容存档于2019-06-30).
參考文獻
一般參考
- Leavens, Gary T.; Dhara, Krishna K. . Leavens, Gary T.; Sitaraman, Murali (编). . 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. . 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. (技术报告). 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. . Springer. 2004. ISBN 3-540-43486-0. Contains a gentler introduction to behavioral subtyping in its various forms in chapter 2.
- Martin, Robert C. (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. . . : 627–632. ISSN 1330-1012. OCLC 894960131.
|journal=
被忽略 (帮助) This paper discusses LSP in the mentioned context.
具體參考
- Liskov, B. . 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. . Prentice Hall. 1988. ISBN 0-13-629031-0.
参閲
- SOLID - “SOLID”中的 L 指代了里氏替换原则
- 類型簽名
- 參考透明度(Referential transparency)
- 求精法 (編程計算)(Refinement (computing))
- 組合優於繼承(Composition over inheritance)
外部連結
- Norvell, T.S. (PDF). 2003 [2022-01-06]. (原始内容 (PDF)存档于2022-01-30).
- Liskov Substitution Principle Explained (页面存档备份,存于)
- SOLID Class Design: The Liskov Substitution Principle (页面存档备份,存于)
- LSP: Liskov Substitution Principle (页面存档备份,存于)
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.