Part 4 of 6 · 2 min read
KISS
The plain solution first.
KISS is short for "keep it simple". HF applies it to patterns. When designing, solve the problem in the simplest way. The aim is a simple design, with no pressure to find a place for some pattern. HF says that a developer who does not use a pattern is not less sophisticated, and that others will admire a simple design. It adds that sometimes the simplest and most flexible answer is a pattern. The advice is to bring one in only when sure that it addresses a real problem, and to consider the simpler solution first.
CC offers a checklist from Kent Beck, the four rules of simple design, in order of importance.
- The design runs all the tests.
- It has no duplication.
- It shows the programmer's intent clearly.
- It uses as few classes and methods as possible.
The order matters. Passing tests comes first. The last rule, fewer classes, has the lowest priority. CC says that keeping the class count low is important, but not above the first three. Do not merge classes to keep a count down if it hides the intent.
CC adds one more point. Tests themselves push design in the right direction. Tightly coupled code is hard to test, so people who write tests end up using interfaces and injection (module 5), which lowers coupling.
In an interview, KISS means a plain first design. Draw the entities and the one or two methods that matter. Add a pattern when the requirements call for it, and say why.
KISS
KISS says to choose the simplest design that meets the need, and to add structure only when a real problem asks for it.
Example: a plain if for two payment types, before any payment interface.
Check yourself: 1. Which of Beck's four rules has the highest priority? 2. When does HF suggest using a pattern? 3. How do tests improve design, according to CC?