Inversion of control
A template method is all well and good, but its use in modern times has greatly declined. This pattern was frequently used to virtualize access to a piece of data (or some other resource) just as in the example from this chapter, that is, the TemplateMethod project discussed earlier, but nowadays we know how to approach such problems in a more decoupled and manageable way.
In a way, a template method tells us that the code doesn't follow the single responsibility principle and that it tries to do too much. It wants to be business logic and something else (a data source, in our case).
Instead of writing subclasses that implement missing functionality, we can take a step back, look at the missing functionality as a whole, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access