在面向对象的程序设计中,里氏替换原则(Liskov Substitution principle)是对子类型的特别定义。它由芭芭拉·利斯科夫(Barbara Liskov)在1987年在一次会议上名为“数据的抽象与层次”的演说中首先提出。
里氏替换原则的内容可以描述为:
“派生类(子类)对象可以在程式中代替其基类(超类)对象。”
以上内容并非利斯科夫的原文,而是译自罗伯特·马丁(Robert Martin)对原文的解读。其原文为:
:Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T.
芭芭拉·利斯科夫与周以真(Jeannette Wing)在1994年发表论文并提出以上的Liskov代換原則。
引用
參考文獻
一般參考
- This paper surveys various notions of behavioral subtyping, including Liskov and Wing's.
*
An updated version appeared: The formalization of the principle by its authors.
- Contains a gentler introduction to behavioral subtyping in its various forms in chapter 2.
- An article popular in the object-oriented programming community that gives several examples of LSP violations.
- This paper discusses LSP in the mentioned context.
具體參考
- A keynote address in which Liskov first formulated the principle.
*
参閲
- SOLID - “SOLID”中的 L 指代了里氏替换原则
*類型簽名
*(Referential transparency)
*(Refinement (computing))
*(Composition over inheritance)
外部連結
*
- [https://medium.com/@wrong.about/liskov-substitution-principle-a982551d584a Liskov Substitution Principle Explained]
*[https://www.tomdalling.com/blog/software-design/solid-class-design-the-liskov-substitution-principle/ SOLID Class Design: The Liskov Substitution Principle]
*[https://medium.com/swlh/lsp-liskov-substitution-principle-24311d1f854 LSP: Liskov Substitution Principle]
评论 (0)