Avoiding Dependencies

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, except under certain circumstances. 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 MP3 player have separate domains. This provides flexibility, such as buying the CD player and the MP3 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 and TV/DVD combinations. Not only has object-oriented design evolved since the first edition of this book was published, but consumer technology has evolved as well. VCRs are not as prevalent as they once were, and DVDs are following the same path. The movement of consumer preferences from VCRs to DVDs to streaming technologies in such a short period of time is a good example of why avoiding dependencies is a preferred design choice at many levels.

You need to determine what is more important in specific situations: 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 far outweighed the risk of lower unit stability (see Figure 9.6).

Image

Figure 9.6. Convenience versus stability.

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

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