Then p(y) should 99: be true for objects y of type S where S is a subtype of T. Barbara Liskov and Jeannette Wing formulated 95: the principle succinctly in a 1994 paper as follows: 97: Subtype Requirement: 98: Let p(x) be a property provable about objects x of type T. 92: It is a semantic rather than merely a syntactic relation because it 93: intends to guarantee semantic interoperability of types in a hierarchy, 94: object types in particular. More formally, the Liskov substitution principle (LSP) 89: is a particular definition of a subtyping relation, called (strong) 90: behavioral subtyping, that was initially introduced by Barbara Liskov in 91: a 1987 conference keynote address entitled Data Abstraction and Hierarchy. 83: Substitutability is a principle in object-oriented programming that states 84: that, in a computer program, if S is a subtype of T, then objects of type 85: T may be replaced with objects of type S (i.e., an object of the type T 86: may be substituted with its subtype object of the type S) without altering 87: any of the desirable properties of that program (correctness, task 88: performed, etc.). 77: The (Liskov) Substitution Principle 78: A variable of a given type may be assigned a value of any subtype, and a 79: method with a parameter of a given type may be invoked with an argument 80: of any subtype of that type. 7: class Rectangle 8: ħ4: /* 75: In Java, S is a subtype of T if S extends or implements T. be careful when you extend a class that 5: //the derived class really does satisfy the "is a" relationship. class LiskovSubstitutionPrincipleViolatedġ: //LiskovSubstitutionPrincipleViolated.java 2: //Illustrates a violation of Liskov's Substitution Principle, for 3: //which see the Wikipedia description quoted at the end of this 4: //file. Use inheritance when you want to alter the behavior implemented by the non.LiskovSubstitutionPrincipleViolated.java Source of LiskovSubstitutionPrincipleViolated.java
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |