3. Operations declaration and inheritance

System Message: WARNING/2 (/home/runner/work/PyZombis/PyZombis/_sources/lectures/TWP25/TWP25_3_en.rst, line 2)

Title underline too short.

Operations declaration and inheritance
=====================================

3.1. Client Class and Improved Account Class

3.1.1. Using the Client and Improved Account Classes

3.2. Inheritance

System Message: WARNING/2 (/home/runner/work/PyZombis/PyZombis/_sources/lectures/TWP25/TWP25_3_en.rst, line 73)

Title underline too short.

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 of Account.

  • self.limit will only be created for classes of type SpecialAccount.

  • Note that we are completely overriding the withdraw method in SpecialAccount.

3.4. Advantages of Inheritance

System Message: WARNING/2 (/home/runner/work/PyZombis/PyZombis/_sources/lectures/TWP25/TWP25_3_en.rst, line 107)

Title underline too short.

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.

3.5. Using all classes

You have attempted of activities on this page