> In general, when one works out the design well in advance before writing code.
One tool available is Behavior/Feature Driven Development which forces you to work out the design well in advance and then implement only the code that makes that design "pass".