Designing templates
As the name suggests, templates define a common template or format in which we can design an algorithmic flow of operations and reuse them when similar kinds of activities are performed. A template is one of the methods of design patterns in Python and can be used effectively while developing frameworks or libraries. Templates emphasize the concept of reusability in programming.
In this section, we will look at creating a class that handles all the common functions of all four counters discussed throughout this chapter, and create a method that handles the template that sequences or pipelines the steps to be executed in all the counters:
- To begin with, let’s create an abstract class named
CommonCounter
, and initialize the class with all the variables that will be used across all four counters. Refer to the following code:from abc import ABC, abstractmethod class CommonCounter(ABC): def __init__(self,items,name,scan,units...