View on GitHub

Bearded-android-docs

LiskovSubstitutionPrinciple

Download this project as a .zip file Download this project as a tar.gz file

Created Tuesday 15 October 2013

See also DesignByContract.

Some rules of thumb to help ensure LSP:

  1. Whenever possible, avoid overriding concrete methods.
  2. If you do, see if you can call the method you are overriding in the overriding method.

Related to LSP is NormalizedHierarchy

Example: Circle-Ellipse Problem

A circle is a special case of an ellipse, so should we use inheritance to model this relationship?
Probably not. While a circle is an ellipse, the Circle Object behaves differently than the Ellipse Object.
Suppose the ellipse class looks like this:

class Ellipse
{
   //bunch of math constants
   int centerX, centerY;
   int h, k;
   int a, b;

   public void stretchX(float s)
   {
       //stretch the ellipse horizontally
   }
}


Backlinks:

OOP:RefactoringLegacyCode OOP:ProgrammingByDifference
comments powered by Disqus