03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

220 CHAPTER 7. EFFECTIVE PROGRAMMING: THE POLYMORPHIC WAY<br />

Note<br />

The binary method problem is encountered when methods in which the<br />

receiver type and argument type should vary together, such as equality<br />

comparisons, must instead use a fixed <strong>for</strong>mal parameter type to<br />

maintain type safety. The problem arises in mainstream object-oriented<br />

languages because only the receiver of a method call is used <strong>for</strong> run time<br />

method selection, and so the argument must be assumed to have the<br />

most general possible type. Existing techniques to solve this problem<br />

require intricate coding patterns that are tedious and error-prone. The<br />

binary method problem is a prototypical example of a larger class of<br />

problems where overriding methods require type in<strong>for</strong>mation <strong>for</strong> their<br />

<strong>for</strong>mal parameters. Another common example of this problem class is<br />

the implementation of event handling (e.g., <strong>for</strong> graphical user interfaces),<br />

where ”callback methods” must respond to a variety of event<br />

types.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!