Pages

Tuesday, March 11, 2008

Solving Bob's Problem

Reading up on Liskov Substitution Principle last night finaly put me over the top to start blogging about software development. I had a copy of Robert C. Martin's article published on the Object Mentor webpage (direct link) where he suggest that deriving Square from Rectangle violated LSP.

This will violated LSP since a client may call SetHeight with one number and SetWidth with another and presume that GetHeight will return what ever number SetHeight was called with - which will of couse not be the case.

He leaves us no solution in his article, so we're left to think that a Square never should inherit a Rectangle. I myself should in this simple case make the objects immutable. Aside from all other benefits it will also make the objects pass the LSP test.

About Me

I've worked with software development since 1994. Desktop applications, web applications and real time embedded software have all been part of my profession through the years. Since 2007 I've had an enormous interest in methodology, trying out plenty of agile practices and read tons of books and blogs on the subject.