Problem Definition

Consider a sales system that supports a sales representative selling a certain kind of computer to end users.

Let's assume the base pieces are defined as in Table 4.1.

The sales person will sell a configuration for a computer such as that in Table 4.2.

Table 4.1. Computer Components
Part Choices
Motherboard + Processor 486, Pentium, PentiumII, Xeon, Pentium III
Case Desktop, Minitower, Fulltower
Drives 4,6,10,13G
Memory 32M, 64M, 128M, 256M, 512M
Monitor 15", 17", 19", 21"
Soundcard Regular, 3D
Video Card Standard, Pro, 3D
Modem None, 28K, 56K, ISDN

Table 4.2. A Basic Computer System
Galaxy Pro Computer System
Motherboard + Processor PentiumII
Case Minitower
Drives 10G
Memory 64M
Monitor 17"
Soundcard Regular
Video Card Pro
Modem 28K
Price $1800

One approach might be to model this computer system as a simple representation of an object that we can sell that contains parts that can be selected (see Figure 4.1). As I show later, this approach is extremely rigid and hampers the ability to extend the system in the future.

Figure 4.1. A representative model of the product configuration


We want a way for the sales department to come up with a configuration from these items and to be able to select them from a list of products. In addition, as new parts are added, we want to be able to add them rapidly to our deployments.

Now let's change the implementation of the Soundboard Class to support a new type of soundcard. This requires first changing the Soundboard Class and potentially breaking any existing code (violating the Open-Closed Principle discussed earlier, or more simply, if it ain't broke, don't touch it) or creating a new class. If the change results in even a minor change to the interface (for example, adding a single new data member), this will cause a ripple effect since the Computer Class must also change. In effect, any change (no matter how small) will force a rebuild and will potentially ripple throughout the entire code base. Basically, we are generating too many classes that are far too rigid. What we need is a better way.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.128.145