In previous chapters we encapsulated our tensorflow graph into a class without discussing it any further. This idea itself is already good coding practice. Having a class responsible to build your graph and exposing only things that are useful for using the model (that is, it’s inputs/outputs) is a good programming practice that will save you lots of time.
It is also common practice to use design patterns in order to solve some software design problems. One of the simplest and most useful design patterns in python is the singleton one. It is used when you want to force the instantiation of a class to only one object, so even if you instantiate this class multiple times in several different places in your project, you will be referencing the same object. In our case if we ask TensorFlow to create multiple nodes or graphs with the same name, it will throw an error. Therefore, we use the singleton pattern while creating the graph to avoid building...