- Published on
KembaraXtra-Computer Science- Object-Oriented Programming (OOP)
I. Paradigms in Programming
myAccount.deposit(25) # Increases myAccount's balance by 25
Key Concept: myAccount is an object (instance of BankAccount). deposit() is a method called on that specific object, modifying its balance field.
I. Paradigms in Programming
- Programming languages support different approaches to programming called paradigms.
- Examples:
- Procedural Programming
- Functional Programming
- Object-Oriented Programming (OOP)
- Languages can support multiple paradigms.
- Definition: A programming paradigm where code and data are grouped together into objects.
- Objects: Logical groupings of data and functionality, designed to model real-world concepts.
- Class-Based Approach: Common in OOP languages.
- Class: A blueprint for an object. Defines the structure and behavior of a type of object.
- Object: An instance of a class. A concrete realization of the class blueprint.
- Methods: Functions defined within a class. They define the actions that an object can perform.
- Fields: Variables declared within a class. They store the data associated with an object.
- Instance Variables (Python): Fields that have different values for each object (instance) of the class. Each object has its own unique value for these fields.
- Class Variables (Python): Fields that have the same value across all objects (instances) of the class. These variables are shared by all objects of the class.
- Class: BankAccount (a blueprint)
- Fields:
- balance (instance variable - each account has a unique balance)
- holder's name (instance variable - each account has a unique name)
- Methods:
- withdraw()
- deposit()
- Fields:
- Objects: Specific bank accounts created from the BankAccount class (instances). These are real accounts with specific names and balances.
- Interaction: We can use the withdraw or deposit methods to modify the balance field of specific bank account objects.
myAccount.deposit(25) # Increases myAccount's balance by 25
Key Concept: myAccount is an object (instance of BankAccount). deposit() is a method called on that specific object, modifying its balance field.
0 Comments