Documenting your new class
1. Documenting your new class
After successfully creating the MortgageCalculator class, you pause to reflect on your work. As a loan officer at PyBank, it's essential to document your class to ensure others can easily understand and build on its functionality.2. Roadmap
Here is an overview of what you've created so far! Now it's time to focus on documentation.3. Your Class Hierarchy
Let's review the class hierarchy. The `BasicCalculator` class you previously built performs basic arithmetic. Its child class, `FinancialCalculator`, provides additional functionality, such as calculating the monthly interest rate from the annual interest rate. You built a `MortgageCalculator` class that inherits from `FinancialCalculator`, which in turn inherited from `BasicCalculator`. Now, follow proper software engineering practices and create a docstring for it.4. Docstrings
You remember that a docstring is a special string in Python used to document modules, functions, classes, and methods. Why is this beneficial? A docstring provides a clear and concise explanation of the code's purpose, making it easier to understand and maintain. Docstrings also enable automatic documentation generation and interactive help features. To create a docstring, make a string literal as the first statement in the definition of a module, class, function, or method. Write an explanation of the module, class, function, or method.5. Add attributes to the Mortgage Calculator class
To create a class for the mortgage calculator, you constructed a subclass derived from the `FinancialCalculator` class. You then invoked `super()` to inherit features from the parent class and defined attributes for the loan amount and the monthly interest rate. Now, add another attribute, `months`, for the number of months using methods inherited from `FinancialCalculator`. Finally, assign the result of a function, `calculate_monthly_payment()`, to a variable that holds the monthly payment amount. The `calculate_monthly_payment()` will be written in the following slides.6. Keep Track of Functionality of Classes
As a developer, how do you keep track of which methods belong to which classes? The `dir()` function comes in handy here. In a terminal, use `dir(ClassName)` to get a list of the methods of a class `ClassName`. The methods are listed in alphabetical order. Note that there is no distinction between methods of the current class and inherited methods. When you apply the `dir()` command to the `MortgageCalculator` class, the methods listed near the bottom are ones you wrote for the classes it inherits from, `FinancialCalculator` and `BasicCalculator`.7. Let's practice!
You've learned how powerful inheritance can be. Now, practice what you've learned!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.