feat(model): introduce transaction hierarchy with deposit, withdraw, and transfer types

This commit is contained in:
2026-06-05 19:20:24 +03:30
parent 281d47463e
commit 8cb8c11260
4 changed files with 143 additions and 27 deletions
@@ -1,38 +1,25 @@
package dev.banking.model;
public class Transaction {
private final TransactionType type;
private final int sourceAccountId;
private final int targetAccountId;
/**
* Base class for all transaction types.
*
* Transactions are immutable and thread-safe.
*/
public abstract class Transaction {
private final int amount;
public Transaction(
TransactionType type,
int sourceAccountId,
int targetAccountId,
int amount
) {
this.type = type;
this.sourceAccountId = sourceAccountId;
this.targetAccountId = targetAccountId;
protected Transaction(int amount) {
if (amount <= 0) {
throw new IllegalArgumentException(
"Transaction amount must be positive."
);
}
this.amount = amount;
}
public TransactionType getType() {
return type;
}
public int getSourceAccountId() {
return sourceAccountId;
}
public int getTargetAccountId() {
return targetAccountId;
}
public int getAmount() {
return amount;
}