Re: 7.0 wishlist?
- From: Joshua Cranmer <Pidgeot18@xxxxxxxxxxxxxxx>
- Date: Thu, 13 Nov 2008 18:14:05 -0500
Andreas Leitgeb wrote:
Joshua Cranmer <Pidgeot18@xxxxxxxxxxxxxxx> wrote:Note, for example, that making a Square class extend a Rectangle (since a Square is-a Rectangle) does not actually work since it would fail to match the Rectangle's contract.
I may not understand your example in all its possible deepness, but
what type of rectangle-related contract do you have in mind, that is not met by a square? I hope it is not something like "width!=height
must be allowed": such types of contracts would thwart almost every "is-a" relation.
This is the example I've seen:
void assertContract(Rectangle r) {
int width = r.getWidth();
r.setHeight(5);
assert width == r.getWidth();
}
The idea that changing the height does not change the width is what is violated. A more general way of putting it is that it violates the contract that properties (most of them, in any case) are distinct and individually modifiable without affecting others.
--
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
.
- Follow-Ups:
- Re: 7.0 wishlist?
- From: Andreas Leitgeb
- Re: 7.0 wishlist?
- References:
- Re: 7.0 wishlist?
- From: Harold Yarmouth
- Re: 7.0 wishlist?
- From: Joshua Cranmer
- Re: 7.0 wishlist?
- From: Harold Yarmouth
- Re: 7.0 wishlist?
- From: Joshua Cranmer
- Re: 7.0 wishlist?
- From: Harold Yarmouth
- Re: 7.0 wishlist?
- From: Joshua Cranmer
- Re: 7.0 wishlist?
- From: Harold Yarmouth
- Re: 7.0 wishlist?
- From: Joshua Cranmer
- Re: 7.0 wishlist?
- From: Harold Yarmouth
- Re: 7.0 wishlist?
- From: Joshua Cranmer
- Re: 7.0 wishlist?
- From: Harold Yarmouth
- Re: 7.0 wishlist?
- From: Joshua Cranmer
- Re: 7.0 wishlist?
- From: Andreas Leitgeb
- Re: 7.0 wishlist?
- Prev by Date: Re: 7.0 wishlist?
- Next by Date: Re: 7.0 wishlist?
- Previous by thread: Re: 7.0 wishlist?
- Next by thread: Re: 7.0 wishlist?
- Index(es):
Relevant Pages
|