O'Reilly logo

Refactoring Workbook by William C. Wake

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 15. Catalog

Note

“Who's in charge here?”

This is a moderate-size example involving both refactoring and development. The goal is to demonstrate how we can use refactoring to explore design decisions and their consequences.

Introduction

Imagine a store selling a variety of items. During a brief design session, we decide there are several classes of interest: Item (something for sale), Catalog (the set of all items), and Query (to find a specific set of items).

Catalog and Query must collaborate to search, but how that collaboration will occur needs to be decided. Imagine a fourth class, Interrogator. It has a method evaluate(catalog, query) that returns a list of items. This method encapsulates the decision about how to handle things.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required