concept Enforce sequence in category software development

appears as: Enforce sequence
Five Lines of Code

This is an excerpt from Manning's book Five Lines of Code.

Doing this has the significant effect of removing the invariant that we have to call map.transform before the other methods. When something needs to be called before something else, we call it a sequence invariant. It is impossible not to call the constructor first, so the invariant is eliminated. This technique can always be used to make sure things happen in a specific sequence. We call this refactoring Enforce sequence [P6.4.1].

The Enforce sequence transformation has two variants: internal and external. The previous example demonstrates the internal version: the target function is moved inside the new class. Here is a side-by-side comparison of the two variants, which mostly offer the same advantages.