6
Bisakah Anda menerapkan pemrograman "berorientasi objek" tanpa kata kunci kelas?
Katakanlah kami ingin memberikan abstraksi "akun" di bank. Inilah satu pendekatan, menggunakan functionobjek dalam Python: def account(): """Return a dispatch dictionary representing a bank account. >>> a = account() >>> a['deposit'](100) 100 >>> a['withdraw'](90) 10 >>> a['withdraw'](90) 'Insufficient funds' >>> a['balance'] 10 """ def withdraw(amount): if amount > dispatch['balance']: return …