Class concept
A class can be thought of as a blueprint that defines the structure of objects in a program. It’s like a mold from which individual objects are created, each with its own attributes and behaviors.
Let’s consider the concept of a class using the example of a BankAccount.
A class is like a blueprint or template for creating objects. In our example, the BankAccount class represents the blueprint for creating individual bank account objects.
classDiagram
class BankAccount {
Int accountNumber
Int Balance
String accountHolder
deposit(amount)
withdraw(amount)
} | ㅤㅤㅤㅤㅤBankAccountㅤㅤㅤㅤㅤ |
|---|
| accountNumber : Int balance : Int accountHolder : String |
| deposit(amount) withdraw(amount) |
Attributes:
- Attributes are characteristics or properties that describe the objects created from the class. For instance, in the case of a
BankAccount, attributes could includeaccountNumber,balance, andaccountHolder.
Methods:
- Methods are functions that define the behavior of the objects created from the class. In the context of a
BankAccount, methods could include operations likedepositandwithdraw, which specify how money can be added to or withdrawn from an account.
This class blueprint defines the structure for creating BankAccount objects. Each object instantiated from this class inherits attributes such as accountNumber, balance and accountHolder. Additionally, the methods such as deposit() and withdraw(), enable the objects to perform operations like adding or withdrawing money.