Interpreter: Product Finder Exercise
Introduction
Imagine an app where you can search for products like sneakers or backpacks by specifying search criteria.Initially, every time a user wanted a new way to search—such as
by color or size, a new finder method was added to a
ProductFinder
class (shown below).Over time, as demand for more search options grew, more and more finder methods were added.
Now, the ProductFinder
is crowded with ways to search, and still more are wanted. This is a classic case of the code smell called
A subtle form of duplication, this smell exists when numerous pieces of code do the same thing using different combinations of data or behavior. [Kerievsky 45]
.
(Reading...)
Formatting Hints:
To format... | use this markup: |
---|---|
source code | {source:lang=java|lineNumbers=false}...{source} (Supported languages: java, cpp, csharp, c, python.) |
bold text | __some text__ |
italicized text | ~~some text~~ |
underlined text | @@some text@@ |
a method or class name | ``myMethod(...)`` |