Liskov Substitution Principle

Barbara Liskov, Interviewed

by Joey deVilla on July 31, 2009

This article also appears in Canadian Developer Connection.

Barbara Liskov The Interview

Over at the IT Manager Connection blog, there’s an interview with Barbara Liskov, who is:

  • The Ford Professor of Engineering at MIT’s Electrical Engineering and Computer Science Department
  • An Institute Professor at MIT
  • The first woman in the United States to earn a Ph.D. in computer science
  • An ACM Turing Award Recipient for both 2008 and 2009
  • An IEEE John von Neumann Medial Recipient for 2004
  • An ACM and American Academy of Arts and Sciences Researcher
  • …and most relevant to us, the “Liskov” in the Liskov Substitution Principle, one of the five SOLID principles for object-oriented design.

In the interview, Barbara talks about winning “the Nobel Prize of computing”, her vision for computing, what got her interested in computers, the challenges that the field still presents to minorities, the work she’s done and her thoughts on up-and-coming tech. If you’d like to listen, here’s the MP3 of Stephen Ibaraki interviewing Barbara Liskov. Stephen also wrote an article containing an abbreviated transcript that appears in IT Manager Connection. Enjoy!

The Liskov Substitution Principle

Small Liskov Substitution Principle poster

In case you’ve forgotten (or perhaps never learned), the Liskov Substitution Principle is:

If for each object o1 of type S there is an object o2 of type T such that for all
programs P defined in terms of T, the behavior of P is unchanged when o1 is
substituted for o2 then S is a subtype of T.

Well, duh. Who didn’t know that?

Object guru Robert C. “Uncle Bob” Martin took this bit of math nerd-speak and paraphrased in a way making it somewhat easier to follow:

Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.

And because I’m nowhere near as smart as Uncle Bob, here’s the way I like to cover it:

If MySubclass is a subclass of MyClass, you should be able to replace instances of MyClass with MySubclass without breaking anything. Sort of like when they changed the actors who played "Darren" in Bewitched or "Becky" in Roseanne.

(Unlike Liskov or Martin, I don’t have to write academic papers, so I can get away with making references to old TV shows.)

As I mentioned earlier, I’ll be writing more about the SOLID principles. Watch this space!

{ 1 comment }