CSE Roadmap

Core tier · about 3 hours · 6 parts

Part 5 of 6 · 2 min read

The limit

Extensible where it is likely, plain elsewhere.

Do not over-build

Extensibility has a cost. Every interface adds a class, a name and a place to look. A design with an interface for everything is hard to read and hard to follow. CA calls this kind of excess needless complexity, and the lesson of YAGNI is the same: do not add a seam for a change nobody expects.

A working rule for rounds:

  • Add a seam where the requirement names several kinds, where a number is a business rule, or where the code touches the outside world.
  • Stay plain where there is one way to do it and no sign that this will change.
  • Wait for the second case. When a second variant appears, extract the interface then. Two cases show the real shape of the variation better than a guess.

Say your choice aloud. "I put an interface for fees because fees vary. I kept the display plain because there is only one." This shows judgement, which interviewers value more than a long list of patterns.

When an interviewer adds a requirement, a good answer has three parts: say what changes, name the class that changes or is added, and name the classes that stay as they are. If the answer is "I would edit five classes", the design has a problem and it is worth saying so, then proposing the seam that would have helped.

Interview angle

Answer in your head first, then open it.

How do you design for change?

Find the axes of change, put an interface at each, and keep the rest plain. A new variant should be a new class, with no edits to existing ones.

What do you do when requirements change in the middle of a round?

Name the new class or the one class that changes, and the ones that do not. If many classes change, say which seam was missing.

How do you refactor safely?

Write tests that pin the current behaviour, change one small thing at a time, run the tests after each step.

Check yourself: 1. When should you wait before adding an interface? 2. What are the three parts of an answer to a change request? 3. What is the cost of too many interfaces?

Words you will meet

Word Meaning
Axis of change A part of the requirement likely to vary
Refactoring Improving structure while behaviour stays the same
Characterization test A test that records what the code does now
Code smell A sign in code that suggests a deeper problem
Magic number A raw number in code with no name explaining it