Why did we create separate files for each object?


In the context of this exercise, why did we create separate files for each object (Vertex and Graph)?


You could have absolutely written all the code within a single file. However, there are some important reasons why keeping them separate is a good idea.

One is the “separation of concerns”. Each file has a distinct concern or purpose. The Graph and Vertex classes are distinct and have their own functionality and implementations, separate from each other.

Another important reason is that it keeps our code cleaner, which makes it easier to maintain and understand. For instance, if we needed to update something for the Graph class, we would only need to look at the graph.py file. If all the files were combined into one long file, it would take longer to find and make changes. This reason can become more apparent when working with many classes.

One other important reason for keeping the files separate is that it gives us the flexibility to use them in other files when we need them. For instance, if I created an algorithm and needed just the Vertex object, I could import that file only.