10.3. Interface Development

Sam and I did not have much time to discuss the new use cases introduced at the beginning of this chapter. The original Search_catalog use case in Chapter 4 seems to imply that the search should return only CDCatalogItems that Sam carries in inventory. Should that filtering be part of the CDCatalogItemCollection interface or should it be done on the list of CDCatalogItems that the interface returns?

Considering separation of concerns simplifies our decision. The job of the CDCatalogItemCollection interface is to find all CDCatalogItems that meet the search criteria for each method. The concern of another class, CDCatalogItemInStoreCollection, is to determine which CDCatalogItems correspond to CDReleases. The interface for CDCatalogItemInStoreCollection looks the same as that for CDCatalogItemCollection. CDCatalogItemInStoreCollection is responsible for checking that the UPCCode for each CDCatalogItem exists in the CDReleaseCollection and returns only CDCatalogItems for which that was true. Figure 10-1 shows the sequence diagram for a search using CDCatalogItemInStoreCollection.

Figure 10-1. CDCatalogItemInStoreCollection sequence diagram

To check the usability of the search interface, Tim and I create a small class that implements the CDCatalogItemCollection interface and returns data for a very small number of CDCatalogItems and Songs. Text ...

Get Prefactoring now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.