Skip to Main Content
Prefactoring
book

Prefactoring

by Ken Pugh
September 2005
Intermediate to advanced content levelIntermediate to advanced
240 pages
6h 28m
English
O'Reilly Media, Inc.
Content preview from Prefactoring

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Understanding Unittest.Mock

Understanding Unittest.Mock

Mario Corchero
Java™ Performance

Java™ Performance

Charlie Hunt, Binu John

Publisher Resources

ISBN: 0596008740Supplemental ContentCatalog PageErrata