Supplement: C++ Code Examples
Example 10-4. C++ Code Fragments: A Switch to Control Which Driver to Use
// C++ CODE FRAGMENT // class ApControl . . . void ApControl::doDraw () { . . . switch (RESOLUTION) { case LOW: // use lrdd case HIGH: // use hrdd } } void ApControl::doPrint () { . . . switch (RESOLUTION) { case LOW: // use lrpd case HIGH: // use hrpd } } |
Example 10-5. C++ Code Fragments: Using Polymorphism to Solve the Problem
// C++ CODE FRAGMENT // class ApControl . . . void ApControl::doDraw () { . . . myDisplayDriver->draw(); } void ApControl::doPrint () { . . . myPrintDriver->print(); } |
Example 10-6. C++ Code Fragments: Implementation of ResFactory
class ResFactory { public: virtual DisplayDriver *getDispDrvr()=0; virtual PrintDriver ... |
Get Design Patterns Explained: A New Perspective on Object-Oriented Design now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.