@@ -0,0 +1,1918 @@
+%22%22%22Template method pattern%0A%0ATemplate Method is a behavioral design pattern. It defines an algorithm's%0Askeleton in a Base class, but lets subclasses redefine certain steps of the%0Aalgorithm. The Base class declares some placeholder methods, and derived classes%0Aimplement them.%0A%22%22%22%0Aimport sys%0Afrom abc import ABC, abstractmethod%0A%0A%0Aclass Algorithm(ABC):%0A%0A    def template_method(self):%0A        %22%22%22Skeleton of operations to perform. DON'T override me.%0A%0A        The Template Method defines a skeleton of an algorithm in an operation,%0A        and defers some steps to subclasses.%0A        %22%22%22%0A        self.__do_absolutely_this()%0A        self.do_step_1()%0A        self.do_step_2()%0A        self.do_something()%0A%0A    def __do_absolutely_this(self):%0A        %22%22%22Protected operation. DON'T override me.%22%22%22%0A        this_method_name = sys._getframe().f_code.co_name%0A        print('%7B%7D.%7B%7D'.format(self.__class__.__name__, this_method_name))%0A%0A    @abstractmethod%0A    def do_step_1(self):%0A        %22%22%22Primitive operation. You HAVE TO override me, I'm a placeholder.%22%22%22%0A        pass%0A%0A    @abstractmethod%0A    def do_step_2(self):%0A        %22%22%22Primitive operation. You HAVE TO override me, I'm a placeholder.%22%22%22%0A        pass%0A%0A    def do_something(self):%0A        %22%22%22Hook. You CAN override me, I'm NOT a placeholder.%22%22%22%0A        print('do something')%0A%0A%0Aclass AlgorithmA(Algorithm):%0A%0A    def do_step_1(self):%0A        print('do step 1 for Algorithm A')%0A%0A    def do_step_2(self):%0A        print('do step 2 for Algorithm A')%0A%0A%0Aclass AlgorithmB(Algorithm):%0A%0A    def do_step_1(self):%0A        print('do step 1 for Algorithm B')%0A%0A    def do_step_2(self):%0A        print('do step 2 for Algorithm B')%0A%0A    def do_something(self):%0A        print('do something else')%0A%0A%0Adef main():%0A    print('Algorithm A')%0A    a = AlgorithmA()%0A    a.template_method()%0A%0A    print('%5CnAlgorithm B')%0A    b = AlgorithmB()%0A    b.template_method()%0A%0Aif __name__ == '__main__':%0A    main()%0A

Add Template Method pattern