Avoiding Dependencies

 <  Day Day Up  >  

When using composition, it is desirable to avoid making objects highly dependent on one another. One way to make objects very dependent on each other is to mix domains. In the best of all worlds , an object in one domain should not be mixed with an object in another domain. We can return again to the stereo example to explain this concept.

By keeping the receiver and the CD player in separate domains, the stereo system is easier to maintain. For example, if the CD component breaks, you can send the CD player off to be repaired individually. In this case, the CD player and the cassette player have separate domains. This provides flexibility such as buying the CD player and the cassette player from separate manufacturers. So, if you decide you want to swap out the CD player with a brand from another manufacturer, you can.

Sometimes there is a certain convenience in mixing domains. A good example of this pertains to the existence of TV/VCR combinations. Granted, it is convenient to have both in the same module. However, if the TV breaks, the VCR is unusable ”at least as part of the unit it was purchased in.

In fact, anyone who has kids and has discovered the wonder of the TV/VCR combination can attest to this dilemma. On long trips, we can take the unit into the car and let the kids watch their favorite videos , thus keeping the incessant chanting of "Are we there yet?" to a minimum. When we are not traveling, which is most of the time, the TV part of the unit is used in the exercise room to pass the time while doing our daily workouts. Unfortunately, on at least two occasions over the years , the VCR part of the unit has broken. This has forced us to take the entire unit to the repair shop. Because the TV is integrated with the VCR, the TV part is obviously unavailable for use while the unit is out for repair. Thus, our exercise time does not pass as quickly. If the TV and VCR were separate components , we could at least use the TV while the VCR is out for repair.

You need to determine whether you want convenience or stability. There is no right answer. It all depends on the application and the environment. In the case of the TV/VCR combination, we decided that the convenience of the integrated unit (for use in travel) far outweighed the risk of lower unit stability (see Figure 9.6).

Figure 9.6. Convenience versus stability.

graphics/09fig06.gif

Mixing Domains

The convenience of mixing domains is a design decision. If the power of having a TV/VCR combination outweighs the risk and potential downtime of the individual components, the mixing of domains may well be the preferred design choice.


 <  Day Day Up  >  


Object-Oriented Thought Process
Object-Oriented Thought Process, The (3rd Edition)
ISBN: 0672330164
EAN: 2147483647
Year: 2003
Pages: 164
Authors: Matt Weisfeld

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net