The halfway marker has been reached in our exercise chain and this article will be on object orientation on a larger scale than in the first article. Again the tool used is Python. However this time the task was not to create classes and then a UML diagram, but rather the opposite. Using a pre-existing UML diagram to create classes that then can be tested with data.
Based on the knowledge from my first task of the series I could with little effort create each class with their private variables, as well as getters and setters for each. To make it a little bit easier to follow along, below is an image over the UML diagram.
The trickier part of the task was to figure out how the relationship between the classes was supposed to work to accommodate the different requirements set by the institution. For that I decided to team up with Emma Axelsson and Amanda Svensson, so that we all could pick each other’s brains for the answers.
We had all structured our classes very similarly and we decided that the best way to keep track of each project was to create a
__str__() method in the project class. The method printed out each property for the project on separate lines, so that the user could clearly see which project was which.
The second to last step of the assignment was where we decided to work with two different methods for storing and validating personnel. My approach was to create a set of people that were specifically tailored for three different projects and then through loops and conditional arguments, add each person iteratively to their suited project. The other approach was to add people to the projects and then validate if they suited or not.
The final step was to calculate the net income of the project over at specified amount of time. This was only based on the budget minus the personnel’s salary.