Bank account class diagram
Savings and deposit accounts inherit from account; a customer holds accounts. The balance is private (-) and changes only through methods: encapsulation.
The diagram
Reading it step by step
- 'Customer' (class): 1 attributes, 0 methods.
- 'Account' (class): 1 attributes, 2 methods.
- 'SavingsAccount' (class): 0 attributes, 1 methods.
- 'FixedDeposit' (class): 1 attributes, 0 methods.
- 'Customer' aggregates 'Account' (holds).
- 'SavingsAccount' inherits from 'Account'.
- 'FixedDeposit' inherits from 'Account'.
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| Customer | Class | holds +customerNo int · → Account(holds) |
| Account | Class | holds -balance long, +deposit(amount) void, +withdraw(amount) bool · ← Customer, SavingsAccount, FixedDeposit |
| SavingsAccount | Class | holds +transfer(to, amount) bool · → Account |
| FixedDeposit | Class | holds +maturity Date · → Account |
Symbols used here
| Symbol | Meaning |
|---|---|
| Class | A box with name, attributes and methods. |
| Inheritance | Solid line from child to parent, hollow triangle at the parent. |
| Aggregation | Hollow diamond at the whole; parts can live alone. |
Diagram text
Paste this text into the editor to get the same picture, then change the names to fit your own work.
# Bank account class diagram
classDiagram
class Customer {
+customerNo int
}
class Account {
-balance long
+deposit(amount) void
+withdraw(amount) bool
}
class SavingsAccount {
+transfer(to, amount) bool
}
class FixedDeposit {
+maturity Date
}
Customer o-- Account : holds
Account <|-- SavingsAccount
Account <|-- FixedDeposit