template method pattern what are we to do when we identify solid pattern of actions that need to be taken in variety of contextseach with its own nuancesfunctions are one form of recipe consider the pattern for calculating !where nn - where else nis solving this for the case where we could simply writefact_ that is fine if the only factorial you are ever going to be interested in is that of fivebut it is way more helpful to have general solution to the problemsuch as thisdef fact( )if return return fact( - def main()print(fact( )print(fact( )print(fact( )if __name__ ="__main__"main(what we see here is an illustration where specific set of steps leads to predictable result functions are really great at capturing this idea of an algorithm or set of steps leading to an expected result for some set of input values it does become more difficult when we begin to think about situations that might be more complicated than simply following predefined set of instructions another consideration is what you would do should you want to use the same steps in different wayor implement the steps using more efficient algorithm it might not be clear from the trivial case of the factorial functionso let' look at more involved example your point of sales system suddenly became popularand now customers want to have all kinds of funny things the chief of these requests is to interface with some third-party system they have been using forever to keep track of stock levels and pricing changes they are not interested in replacing the existing systembecause there are customers who are already using itso you have to do the integration