Article:
 |
|
Advanced OOP: Multimethods
|
| Subject: |
|
Not sure where one would use this? |
| Date: |
|
2003-06-17 23:24:30 |
| From: |
|
anonymous2
|
|
|
|
Hi,
As a person who has built object-oriented
systems in C++, Python, and perl I'm a
bit confused by the examples chosen.
Eg. I almost never have to switch on the
type of something, except perhaps as a
safety check on a method's argument.
Perhaps the next article could be
about changing an existing class
which has a deep inheritance hierarchy
to use Dispatch. Eg. SimpleHTTPServer.
Thanks.
|
Showing messages 1 through 3 of 3.
-
Not sure where one would use this?
2003-09-22 12:45:19
anonymous2
[View]
-
Not sure where one would use this?
2003-06-18 10:12:00
quilty
[View]
-
Multimethods Help GUI Programming
2003-06-18 08:56:41
chromatic | 
[View]
shape.intersect(Shape bar)
{
bar.dd_intersect(*this);
}
The call to bar.intersect will not go to shape.intersect, but to the overloaded function closest to the true type of bar - might be shape, might be circle, rectangle, etc. Better, that call will also know the detailed type of the first object, hence
circle.dd_intersect(Circle foo)
circle.dde_intersect(Square foo)
...
You end up with, to quote from a very old text game, a maze of twisty functions, all alike - except where there are special cases.
The general case is implemented in Shape; the special cases are handled where they are needed.
The best part, for my needs when I've used this, is that you can have the fall-back situation be an error in the base class.