Path 3: Process(catalog.data, query.data)


Path 3: Process(catalog.data, query.data)

In the first path, we passed the query to the catalog. In the second path, we passed the catalog to the query. Each of these two ways couples the classes to each other: One must know about the other. A third approach might be to let Interrogator.evaluate() take some information from the catalog and combine it with some information from the query, so that only Interrogator.evaluate() knows both classes.

Exercise 89 FilterEnumerator.
  1. Make Catalog provide an enumerator of its items. Make Query determine whether an item is acceptable. (Both classes know items, but neither knows the other.) Create a FilterEnumerator class: It's an enumerator that takes another enumerator and a query and returns only those items that match the query. Interrogator will set up the objects and use the new enumerator.

  2. This is an example of a pattern. Which one?

  3. What are the performance implications?

See Appendix A for solutions.

Exercise 90 Other Approaches.

Are there other approaches that keep Query and Catalog from knowing about each other?




Refactoring Workbook
Refactoring Workbook
ISBN: 0321109295
EAN: 2147483647
Year: 2003
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net