Solving with Special Cases

Given the two different CAD/CAM systems described in Chapter 3, “A Problem That Cries Out for Flexible Code,” how do I build an information-extraction system that will look the same to a client object regardless of which CAD/CAM system that I have?

In thinking how to solve this problem, I reasoned that if I can solve it for slots, I can use that same solution for cutouts, holes, etc. In thinking about slots, I saw that I could easily specialize each case. That is, I'd have a Slot class and make a derivation for Slots when I had the V1 system and another derivation when I had a V2 system. I show this in Figure 4-1.

Figure 4-1. The design for slots.

I complete this solution by extending it for each of the feature types, ...

Get Design Patterns Explained: A New Perspective on Object-Oriented Design now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.