mardi 20 juin 2017

Implementing the best model for a bank module

I am implementing a bank module in c# which contains a savings account, a checkings account and an easy saving account. All accounts have an owner and a balance and all of them can withdraw and deposit money but they can't withdraw more than the balance. Till here, very easy. Now, our savings account have a new method applyInterest and checkingsAccount a method deductFees and easySavinAccount have both. What I thought about is using an abstract class Account:

 public abstract class Account
{
    protected string owner { get; set; }
    //always use decimal especially for money c# created them for that purpose :)
    protected decimal balance { get; set; }
    public void deposit(decimal money)
    {
        if (money >= 0)
        {
            balance += money;
        }
    }
    public void withdraw(decimal money)
    {
        if (money > balance)
        {
            throw new System.ArgumentException("You can't withdraw that much money from your balance");
        }
        else balance -= money;
    }
}

Which will be inherited by all 3 classes. Is there a design pattern suited to implement this in a better way? Especially for easySaveAccount maybe composition can help?

Thanks!

Aucun commentaire:

Enregistrer un commentaire