Hear us Roar
Article:
 |
|
Advanced OOP: Multimethods
|
| Subject: |
|
Not sure where one would use this? |
| Date: |
|
2003-06-18 10:12:00 |
| From: |
|
quilty
|
Response to: Not sure where one would use this?
|
The anonymous poster who wrote:
|has built object-oriented ...I almost never have
|to switch on the type of something, except perhaps
|as a safety check on a method's argument.
Seems to have missed the point of the article, and probably of OOP. I can barely imagine how you could write ANY OOP program that did not switch on the type of something--that's almost the entire point of OOP.
Now, of course, switching on type is not done mostly by 'switch' or 'if' or 'case' statements in OOP. It's mostly done on the *type of the object*. If you have a parent class, Super, that implements a .foo() method, and a child class, Sub, that specializes .foo(), then every time you call "instance.foo()" you are switching on the type of -instance-. And if you create a subclass in the first place, it is almost always so that the subclass can work in (some of) the same contexts as the parent (by implicitly switching on type).
|
|
| |