3. Operations declaration and inheritance¶
Add the method
statementto theAccountclass that prints a list of deposit and withdrawal operations.Change the
__init__method to use thedepositmethod to initialize the balance.
3.2. Inheritance¶
Object inheritance allows us to modify our classes by adding or modifying attributes and methods based on the previous class.
We will create special accounts where we can withdraw more money than the balance, up to a certain limit.
Deposit, withdrawal, and summary operations continue as a regular account.
3.3. Special Account Class¶
Note that we wrote
Accountin parentheses.SpecialAccountinherits the methods and attributes ofAccount.self.limitwill only be created for classes of typeSpecialAccount.Note that we are completely overriding the
withdrawmethod inSpecialAccount.
3.4. Advantages of Inheritance¶
We have made minimal changes to our program, maintaining previous functionality and adding new features.
It was possible to reuse account methods.
Therefore, the definition of the
SpecialAccountclass was much simpler, including only the different behavior.
