Skip to content
Preptima

Top 4 Refactoring Interview Questions

Browse 4 real-world technical and behavioral interview questions about Refactoring. Review scenarios, edge cases, and architectural best practices.

A test that has passed for a year starts failing after a refactor that was supposed to change nothing. Is it a bug or a bad test?

Work out what the test was actually asserting. If it pins behaviour a user depends on, the refactor changed behaviour and the test did its job; if it pins an implementation detail, it never had value and the failure is the cost of having written it that way.

mediumconcept

Give me a real single-responsibility violation you have seen, and how would you refactor it?

A class violates SRP when it has more than one reason to change, not when it has more than one method; the refactor is to split along the axes that have independently churned, such as pricing rules, persistence, and presentation, and to stop splitting once each piece has its own requester.

mediumconcept

When would you use the strategy pattern instead of inheritance?

Use the strategy pattern instead of inheritance when behaviour varies independently from object identity. Composition avoids subclass explosion, enables runtime swapping and makes algorithms easier to test.

mediumconcept

This interface has twelve methods and every implementation throws UnsupportedOperationException for four of them. What went wrong, and how would you fix it?

The interface was assembled from the union of what implementations do rather than from what any one caller needs, so no implementation can honour the whole contract. Split it by client into role interfaces, working from the call sites rather than from the classes.

mediumconcept