LiskovCheck: Semi-Automatic Liskov Substitution Principle Adherence Check

February 13, 2011 at 9:50 pm Leave a comment

LiskovCheck.exe is a command line utility which scans .NET assemblies for inheritance relationships and lists them in English sentences such as (from nunit.framework.dll):

  • “It looks like a LessThanConstraint and behaves like a ComparisonConstraint.”
  • “It looks like an AssertionHelper and behaves like a ConstraintFactory”.

The first sentence sounds about right, but the second one raises eyebrows: One could swap things and say “It looks like a ComparisonConstraint and behaves like a LessThanConstraint.”  However, “It looks like a ConstraintFactory and behaves like an AssertionHelper” makes less sense. (Disclaimer: I haven’t looked at the nunit source – no idea what this is.)

From LiskovCheck’s SpecFlow acceptance tests:

Feature: Semi-automatic check for adherence to the Liskov Substitution Principle.

Definition of the Liskov Substitution Principle:

“Liskov substitution principle (LSP) is a particular definition of a
subtyping relation, called (strong) behavioral subtyping.”
(from http://en.wikipedia.org/wiki/Liskov_substitution_principle)

…also known as:

“If it looks like a duck, quacks like a duck, but needs batteries – you probably have the wrong abstraction.”
(from http://www.lostechies.com/blogs/derickbailey/archive/2009/02/11/solid-development-principles-in-motivational-pictures.aspx )

Scenario: A subtype is more likely to adhere to the Liskov Substitution Principle.

Given a DLL named Zoo.dll with a “Duck” class which inherits from “Animal”
When I run “liskovcheck Zoo.dll”
Then the words “It looks like a Duck and behaves like an Animal” should be on the screen.

Scenario: A subtype is less likely to adhere to the Liskov Substitution Principle

Given a DLL named Zoo.dll with a “MerganserDuck” class which inherits from “TransistorRadio”
When I run liskovcheck.exe with the argument ‘Zoo.dll'”
Then the words “It looks like a MerganserDuck and behaves like a TransistorRadio” should be on the screen.

The project is on GitHub at https://github.com/robertreppel/LiskovCheck.

To try it out:

  • On https://github.com/robertreppel/LiskovCheck click “Downloads” and download LiskovCheck-0.0.1.zip.
  • Unzip the file.
  • Open a command window in the LiskovCheck-0.0.1 folder and run (e.g.) ‘liskovcheck Ninject.dll’.
  • You may need to “Unblock” a downloaded .dll file  first, by right clicking it, going to “Properties” and selecting “Unblock”.

I wrote LiskovCheck as an excuse to play around with Ninject, SpecFlow and OpenWrap.

For more information, see http://birding.about.com/od/birdprofiles/tp/typesofducks.htm.

 

 

Advertisements

Entry filed under: Architecture & Design, Software Development.

Zombie Agile: Bad Things Done Right Making commitments: Meeting deadlines vs. maximizing throughput

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Twitter

   @robertreppel

%d bloggers like this: