From the Ruby patterns book that I'm reading, I'm doing a kind of summary of each pattern read. This is the first one. What do we need to do to apply this pattern, well this is what this post is going to tell.
Steps:
- Find out
the basic flow of the process that we think that we can apply this pattern.
-Define an abstract base class with a master
method that performs the basic steps already listed, but that leaves the
details of each step to a subclass.
So the base class defines abstract methods and on the subclasses we define the methods that are going to perform the real actions.
This is GoF pattern.
Also something that clearly explains what is this pattern is:
"The general
idea of the Template Method pattern is to build an abstract base class with a
skeletal method. This skeletal method (also called a template method) drives the bit of the processing
that needs to vary, but it does so by making calls to abstract methods, which
are then supplied by the concrete subclasses. We pick the variations that we
want by selecting one of those concrete subclasses.
Non
abstract methods that can be overridden in the concrete classes of the Template
Method pattern are called hook methods. Hook methods permit the concrete
classes to choose
1- to
override the base implementation and do something different or
2- to
simply accept the default implementation."
Bibliography:
Olsen,
R. (s.f.). Dessign Patterns in Ruby.

No hay comentarios:
Publicar un comentario