The Null Object Pattern
Learn about the null object pattern.
We'll cover the following...
The null object pattern is an idea that relates to the good practices that were previously studied. Here, we are formalizing them, and giving more context and analysis to this idea.
How does the null object pattern work
The principle is rather simple—functions or methods must return objects of a consistent type. If this is guaranteed, then clients of our code can use the objects that are returned with polymorphism, without having to run extra checks on them.
We've explored how the dynamic nature of Python made things easier for most design patterns. In some cases, they disappear entirely, and in others, they are much easier to implement. The main goal of design patterns as they were originally thought of is that methods or functions should not explicitly name the class of the object that they need in order to work. For this reason, they propose the creation of interfaces and a way of rearranging the objects to make them fit these ...