Contents
Why Liskov Substitution Principle is important?
The Liskov Substitution Principle is the third of Robert C. Martin’s SOLID design principles. It extends the Open/Closed principle and enables you to replace objects of a parent class with objects of a subclass without breaking the application. This requires all subclasses to behave in the same way as the parent class.
What do you mean by mental substitution?
The replacement of one thing with another. In psychoanalytic theory, it denotes the replacement of unacceptable emotions or unattainable goals with alternative feelings or achievable aims.
Is substitution a defense mechanism?
Psychiatry An unconscious defense mechanism through which an unattainable or unacceptable goal, emotion, or object is replaced by one that is more attainable or acceptable. See Ego defense mechanism.
What is an example of attribute substitution?
Attribute substitution explains the persistence of some illusions. For example, when subjects judge the size of two figures in a perspective picture, their apparent sizes can be distorted by the 3D context, making a convincing optical illusion.
Which is an example of violation of the Liskov substitution principle?
A classic example of violation of the Liskov Substitution Principle is the Rectangle – Square problem. The Square class extends the Rectangle class and assumes that the width and height are equal. Consider the following class.
When did Barbara Liskov introduce the substitution principle?
In other words, derived classes should be replaceable for their base types, i.e., a reference to a base class should be replaceable with a derived class without affecting the behavior. The Liskov Substitution Principle represents a strong behavioral subtyping and was introduced by Barbara Liskov in the year 1987.
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.