Avoiding the reuse of names
In this example, let’s look at another best practice of how to use variable or class names such that the reusability aspect of your code is preserved. Sometimes it might seem easy to reuse the same class or variable names while writing code in a sequence. Reusing names will make it difficult to reuse the classes, variables, methods, or functions in your code as calling them in multiple scenarios will be impacted since the same names are reused for different elements.
Let’s look at an example to understand the method that is not preferred. Let’s define two classes for Branch
with a method named maintenance_cost
with different definitions.
The first Branch
class is defined as follows:
class Branch:
def maintenance_cost(self, product_type, quantity):
self.product_type = product_type
self.quantity = quantity...