FAQ 4.09 What is the inversion of control exhibited by frameworks?

FAQ 4.09 What is the "inversion of control" exhibited by frameworks?

graphics/new_icon.gif

The Hollywood model: Don't call us, we'll call you.

In traditional applications, the application programmer writes the main event loop and this "main program" reaches out and calls reusable library routines as needed. This is "piecewise reuse": the idea is to reuse little pieces of software but leave it up to the application programmer to write the main program. In this approach, the called chunks of software are the reusable assets and the main program is the "glue code" that is application specific.

Frameworks are just the opposite: the framework not the application code controls the flow of execution, and the framework reaches out and calls the application-specific code written by the application developer as needed. This is made possible because the framework is specially designed to call virtual functions to perform operations that are expected to be application specific. Thus, the application programmer specializes the framework by overriding these virtual functions as necessary (see FAQ 2.24).

This inversion of control is a powerful and useful concept, but it is initially quite uncomfortable for developers and their managers. For some reason, everyone emotionally equates the word "reuse" with calling little chunks of reusable code; they have a hard time seeing that frameworks (where reuse involves a big chunk of reusable code calling small chunks of application-specific code) provide higher degrees of reuse.



C++ FAQs
C Programming FAQs: Frequently Asked Questions
ISBN: 0201845199
EAN: 2147483647
Year: 2005
Pages: 566
Authors: Steve Summit

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net