10.5. Interface Splitting

The actions in the RentalOperations class introduced in Chapter 8 are definitely separate from the actions for searching a catalog. The search operations go into their own class, CatalogOperations. The only overlap is that methods in CatalogOperations need to find out if a particular CDDisc is rented, by invoking is_cd_disc_rented( ). That method is currently in RentalOperations.

Status operations do not affect a system's state. They are just reporting mechanisms for the state of an object. We split the current RentalOperations interface into two interfaces: RentalOperations and StatusOperations. The rental status operation (is_cd_disc_rented( )) is placed in StatusOperations.

Now, CatalogOperations needs StatusOperations, but it does not need RentalOperations, as shown in Figure 10-2. Splitting the interfaces allows us to better control the access to each function ("If You Forget Security, You're Not Secure"). The program used by a customer to perform catalog searches involves CatalogOperations, which has access to StatusOperations but not to RentalOperations.

Figure 10-2. Split interfaces

SPLIT INTERFACES

Split a single interface into multiple interfaces if multiple clients use different portions of the interface.[*]

[*] A reviewer suggested that you could find more information on splitting interfaces in Large-Scale C++ Software Design by John ...

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.