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
@@ -0,0 +1,57 @@
package dev.banking.model;
/**
* Represents a transfer operation between two accounts.
*/
public final class TransferTransaction
extends Transaction {
private final int sourceAccountId;
private final int targetAccountId;
public TransferTransaction(
int sourceAccountId,
int targetAccountId,
int amount
) {
super(amount);
if (sourceAccountId < 0) {
throw new IllegalArgumentException(
"Invalid source account id."
);
}
if (targetAccountId < 0) {
throw new IllegalArgumentException(
"Invalid target account id."
);
}
if (sourceAccountId == targetAccountId) {
throw new IllegalArgumentException(
"Source and target accounts must be different."
);
}
this.sourceAccountId = sourceAccountId;
this.targetAccountId = targetAccountId;
}
public int getSourceAccountId() {
return sourceAccountId;
}
public int getTargetAccountId() {
return targetAccountId;
}
@Override
public String toString() {
return "TransferTransaction{" +
"sourceAccountId=" + sourceAccountId +
", targetAccountId=" + targetAccountId +
", amount=" + getAmount() +
'}';
}
}