Contents
- 1 Where is Liskov Substitution Principle used?
- 2 What are the possible signs of not implementing Liskov Substitution Principle?
- 3 What is the substitution property?
- 4 What are the 8 properties of equality?
- 5 How is the substitution principle used in an object oriented program?
- 6 How can a subclass break a superclass method’s contract?
Where is Liskov Substitution Principle used?
The Liskov Substitution Principle in practical software development. The principle defines that objects of a superclass shall be replaceable with objects of its subclasses without breaking the application. That requires the objects of your subclasses to behave in the same way as the objects of your superclass.
When the Liskov Substitution Principle is not followed?
Liskov Substitution Principle is an extension of the Open Close Principle and is violated when you have written code that throws “not implemented exceptions” or you hide methods in a derived class that have been marked as virtual in the base class.
What are the possible signs of not implementing Liskov Substitution Principle?
Some good indicators to identify LSP violations are:
- Conditional logic (using the instanceof operator or object. getClass().
- Empty, do-nothing implementations of one or more methods in subclasses.
- Throwing an UnsupportedOperationException or some other unexpected exception from a subclass method.
What is the substitution property of equality?
The substitution property of equality, one of the eight properties of equality, states that if x = y, then x can be substituted in for y in any equation, and y can be substituted for x in any equation.
What is the substitution property?
Substitution Property: If two geometric objects (segments, angles, triangles, or whatever) are congruent and you have a statement involving one of them, you can pull the switcheroo and replace the one with the other.
What are the 5 properties of equality?
Following are the properties of equality:
- Reflexive property of equality: a = a.
- Symmetric property of equality:
- Transitive property of equality:
- Addition property of equality;
- Subtraction property of equality:
- Multiplication property of equality:
- Division property of equality;
- Substitution property of equality:
What are the 8 properties of equality?
Terms in this set (8)
- Substitution Property of Equality.
- Division Property of Equality.
- Multiplication Property of Equality.
- Subtraction Property of Equality.
- Addition Property of Equality.
- Symetric Property of Equality.
- Reflexive Property of Equality.
- Transitive Property of Equality.
What is the original definition of the Liskov substitution principle?
Join the DZone community and get the full member experience. The Liskov substitution principle is the L in the well-known SOLID acronym. The original principle definition is as follows: Methods that use references to base classes must be able to use objects of derived classes without knowing it.
How is the substitution principle used in an object oriented program?
At a high level, the LSP states that in an object-oriented program, if we substitute a superclass object reference with an object of any of its subclasses, the program should not break. Say we had a method that used a superclass object reference to do something:
What happens if a subclass violates the LSP?
Every subtype is expected to stick to this contract. If a subclass does not adhere to the superclass’s contract, it’s violating the LSP. This makes sense intuitively – a class’s contract tells its clients what to expect. If a subclass extends or overrides the behavior of the superclass in unintended ways, it would break the clients.
How can a subclass break a superclass method’s contract?
If a subclass does not adhere to the superclass’s contract, it’s violating the LSP. This makes sense intuitively – a class’s contract tells its clients what to expect. If a subclass extends or overrides the behavior of the superclass in unintended ways, it would break the clients. How can a method in a subclass break a superclass method’s contract?