using System; namespace ATM.Business { /**////<summary> /// class Account ///</summary> //at first , I named this class as Operate , because I think this class can read, //write money numbers from and to database , also , users can transfer their //money to someone else or their other cards . but my friend tell me //if I named the class like that cause a bad smell when refectoring. publicclass Account { privatedouble _money; //I use property money here to return user`s money read from the database //this is a ENCAPSULATION , which means others can access data in this class //without the class exposing its internal structure. //and , sometimes , the bank didn't allow user withdraw all of the money from //his account . so , property money here can return _money*0.999 to let //user cann't see his real money number. publicdouble money { get { return _money; } } //this is a fake method privatebool getMoneyFromDatabaseByCardID(string CID) { //assume I can get user`s money from database by param CID (Card ID) //and assume money get from db is set to 1234.5 by default. this.setMoney(1234.5); returntrue; } //this is also a fake method working for referring the data access layer //to save changes to the database and for easy ways , we assume //it returns true always , so I can set the return type of this dummy //method as void privatevoid setMoneyChangesToDatabaseByCardID(string CID) { } //sometimes the bank maybe need to operate the user's account directly //here provide this method to implement it. privatebool setMoney(double money) { //assume I can get money from database by UserID here. //now what I must do is charge if the money stored in database is available if(money<=0) { //the card of this user is overdraw , and we assume that bank forbid its user //overdraw. returnfalse; } elseif(money>=1000000) { //assume the bank limit money in this kind of card more than 1,000,000 returnfalse; } else { //available this._money=money; returntrue; } } //put a sum of money to the bank for safekeeping publicbool deposit(double money) { if((money<=0)||(money+this._money>=1000000)) { returnfalse; } else { _money+=money; returntrue; } } //take money from bank publicbool withdraw(double money) { if((this._money-money<=0)||(money<0)) { returnfalse; } else { _money-=money; returntrue; } } //transfer money from a user to a another user publicbool transfer(Account act,double money) { if(this.withdraw(money)) { //if this user has enough money to others , then check if the acceptor //can accept the money because this bank limit money can not more than //1,000,000 if(act.deposit(money)) { returntrue; } else { //give money back to the money-giving user because we had withdrew //the money from his/her account , because of the money-receiving //user cann't receive the money because some exceptions. this.deposit(money); returnfalse; } } else { returnfalse; } } //default constructor //be carefull that I set the type of CardID as string //basic guideline: use integer for MATHEMATICALLY operable numbers //just set phoneNumber or CardID to string format , 'cause you needn't add or //multiply these public Account(string CardID) { getMoneyFromDatabaseByCardID(CardID); } //the disconstrutor method calls a dummy method which can write changes //to database (error thinking) ~Account() { setMoneyChangesToDatabaseByCardID(CID); } } }