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.

Exercise 77 Evaluate.

Should the core of evaluate() 's implementation be

  1. catalog.itemsMatching(query)

  2. query.matchesIn(catalog)

  3. process(catalog.data, query.data) (that is, this module uses information from each to decide what to do)

Argue for and against each choice, and suggest others if you can.

See Appendix A for solutions.




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