Skip to Content
Design Patterns Explained: A New Perspective on Object-Oriented Design
book

Design Patterns Explained: A New Perspective on Object-Oriented Design

by Alan Shalloway, James R. Trott
July 2001
Beginner to intermediate
368 pages
6h 52m
English
Addison-Wesley Professional
Content preview from Design Patterns Explained: A New Perspective on Object-Oriented Design

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Design Patterns Explained: A New Perspective on Object-Oriented Design, Second Edition

Design Patterns Explained: A New Perspective on Object-Oriented Design, Second Edition

Alan Shalloway, James R. Trott
Design It!

Design It!

Michael Keeling

Publisher Resources

ISBN: 0201715945Purchase book