top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is Liskov Substitution principle in Java?

+1 vote
360 views
What is Liskov Substitution principle in Java?
posted Apr 1, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes

Liskov Substitution principle (LSP) states that "Methods that use references to the base classes must be able to use the objects of the derived classes without knowing it." or in other words,
a.if a class B is a subclass of a class A,
b.if A has a method f(),
c.if b is an instance of B and a an instance of A,
d.then in all the parts of the code using “a.f()” should be able to use” b.f()” without modifying the behavior of the code.

Read this article from queryhome where LSP is explained with an example:
http://tech.queryhome.com/121052/liskov-substitution-principle-concept-object-oriented-design

answer Apr 1, 2016 by Shivam Kumar Pandey
0 votes

According to Liskov Substitution Principle, Subtypes must be substitutable for super type i.e. methods or functions which uses super class type must be able to work with object of sub class without any issue". LSP is closely related to Single responsibility principle and Interface Segregation Principle. If a class has more functionality than subclass might not support some of the functionality ,and does violated LSP. In order to follow LSP SOLID design principle, derived class or sub class must enhance functionality, but not reduce them. LSP represent "L" on SOLID acronym.

answer Oct 12, 2016 by Arun Angadi
...