3. Operations declaration and inheritance¶
Add the method
statement
to theAccount
class that prints a list of deposit and withdrawal operations.Change the
__init__
method to use thedeposit
method 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
Account
in parentheses.SpecialAccount
inherits the methods and attributes ofAccount
.self.limit
will only be created for classes of typeSpecialAccount
.Note that we are completely overriding the
withdraw
method 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
SpecialAccount
class was much simpler, including only the different behavior.