A Banking Class Example
Following the tutorials in
Educative I wrote my first class with inheritance. It’s basic but it works.
It’s a far cry from what I’ve done previously in
C# and the
self takes some getting used to.
I’m running a
pep8 (flake8) plugin in my
Vim to check my code, but there is a fair bit of confusion happening with my autocomplete. It’s messing with my head, particularily here in
Goyo editing mode.
Here’s the class I’ve written, admist all this confusion.
def __init__(self, title=None, balance=0):
self.title = title
self.balance = balance
def withdrawal(self, amount):
self.balance -= amount
def deposit(self, amount):
self.balance += amount
def __init__(self, title=None, balance=0, interestRate=0):
# calling the constructor from the parent class
self.interestRate = interestRate
print(self.balance * self.interestRate / 100)
a = SavingsAccount("Mark", 5000, 5)
I’m chuffed to be able to do it through
Vim and run it in a terminal below
the code. Similar experience to
VS Code? Kind of but there’s a feeling of
knowing the how and a little of the why.
Okay, on to Polymorphism.