//: C10:TemplateMethod.cpp // From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison. // (c) 1995-2004 MindView, Inc. All Rights Reserved. // See source code use permissions stated in the file 'License.txt', // distributed with the code package available at www.MindView.net. // Simple demonstration of Template Method. #include using namespace std; class ApplicationFramework { protected: virtual void customize1() = 0; virtual void customize2() = 0; public: void templateMethod() { for(int i = 0; i < 5; i++) { customize1(); customize2(); } } }; // Create a new "application": class MyApp : public ApplicationFramework { protected: void customize1() { cout << "Hello "; } void customize2() { cout << "World!" << endl; } }; int main() { MyApp app; app.templateMethod(); } ///:~