public class Bankprogram {
public static void Main() {
var moneyTransactionService = new MoneyTransactionService();
var transaction = CreateTransaction();
moneyTransactionService.TransferFunds(transaction);
private static Transaction CreateTransaction() {
var meridiumAccount = new Account();
meridiumAccount.isValid = true;
meridiumAccount.overDraftLimit = 10000000;
var employeeAccount = new Account();
employeeAccount.isValid = true;
source = meridiumAccount,
target = employeeAccount,
public class Transaction {
public Account source { set; get; }
public Account target { set; get; }
public double amount { set; get; }
public static class AccountTransaction {
public static void SaveTransaction(Account source, Account target, double amount) {}
public bool isOverDraftAllowed { set; get; }
public bool isValid { set; get; }
public double overDraftLimit { set; get; }
public double balance { set; get; }
public void Debit(double amount) {}
public void Credit(double amount) {}
public class MoneyTransactionService {
private void ValidateAccount(Account account) {
if (account == null || account.isValid == false ) {
throw new Exception("Illegal account");
private void CheckForOverDraft(Account account, double amount) {
if (account.isOverDraftAllowed) {
if ((account.balance - amount) < 0) {
throw new Exception("Insuffient ballance");
if (((account.balance + account.overDraftLimit) - amount) < 0 ) {
throw new Exception("Insuffient ballance");
private void ValidateAmount(double amount) {
if (amount < 0 || amount > double.MaxValue) {
throw new Exception("Illegal amount");
private void ValidateTransaction(Transaction transaction) {
ValidateAmount(transaction.amount);
ValidateAccount(transaction.source);
ValidateAccount(transaction.target);
private void MakeTransfer(Transaction transaction) {
var amount = transaction.amount;
var sourceAccount = transaction.source;
var targetAccount = transaction.source;
sourceAccount.Credit(amount);
targetAccount.Debit(amount);
AccountTransaction.SaveTransaction(sourceAccount,targetAccount, amount);
public void TransferFunds(Transaction transaction) {
ValidateTransaction(transaction);
CheckForOverDraft(transaction.source, transaction.amount);
MakeTransfer(transaction);