feat(model): introduce transaction hierarchy with deposit, withdraw, and transfer types
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user