3. Operations declaration and inheritance

3.1. Client Class and Improved Account Class

Activity: 3.1.1 ActiveCode (ac_l25_3a_en)

3.1.1. Using the Client and Improved Account Classes

Activity: 3.1.1.1 ActiveCode (ac_l25_3b_en)

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

Activity: 3.3.1 ActiveCode (ac_l25_3c_en)

  • 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

  • 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

Activity: 3.5.1 ActiveCode (ac_l25_3d_en)

You have attempted 1 of 5 activities on this page