Refactoring Workbook
To explore another way of doing things, we'll start over with the same setup() routine, but a different test: Query query = new Query("shirt"); List list = query.matchesIn(catalog); AssertEquals(2, list.size());
You probably found that List wasn't the most convenient type; you'd really prefer a Set (so the OrQuery doesn't produce duplicates). You can change the List types to Sets, but you might also take this as a warning: Perhaps the result wants to be its own object, or perhaps the result of a query is another catalog.
The first optimization exposed information about the query (words to filter by) to the catalog. The second optimization exposed information about the catalog (sets of items) to the query. |