1. BankAccountExternal.cs
using System;public class BankAccountExternal{public decimal GetAmount(){return 2000.00m;}}
2. BankAccountPrivate.cs
using System;class BankAccountPrivate{private string m_name;public string CustomerName{get { return m_name; }set { m_name = value; }}}
3. BankAccountProtected.cs
using System;class BankAccountProtected{public void CloseAccount(){ApplyPenalties();CalculateFinalInterest();DeleteAccountFromDB();}protected virtual void ApplyPenalties(){// deduct from account}protected virtual void CalculateFinalInterest(){// add to account}protected virtual void DeleteAccountFromDB(){// send notification to data entry personnel}}
4. BankAccountPublic.cs
using System;class BankAccountPublic{public decimal GetAmount(){return 1000.00m;}}
5. CheckingAccount.cs
using System;class CheckingAccount : BankAccountProtected{protected override void ApplyPenalties(){Console.WriteLine("Checking Account Applying Penalties");}protected override void CalculateFinalInterest(){Console.WriteLine("Checking Account Calculating Final Interest");}protected override void DeleteAccountFromDB(){base.DeleteAccountFromDB();Console.WriteLine("Checking Account Deleting Account from DB");}}
6. InternalInterestCalculator.cs
using System;internal class InternalInterestCalculator{// members go here}
7. SavingsAccount.cs
using System;class SavingsAccount : BankAccountProtected{protected override void ApplyPenalties(){Console.WriteLine("Savings Account Applying Penalties");}protected override void CalculateFinalInterest(){Console.WriteLine("Savings Account Calculating Final Interest");}protected override void DeleteAccountFromDB(){base.DeleteAccountFromDB();Console.WriteLine("Savings Account Deleting Account from DB");}}
8. Program.cs
using System;class Program{static void Main(){BankAccountPublic bankAcctPub = new BankAccountPublic();// call a public methoddecimal amount = bankAcctPub.GetAmount();Console.WriteLine("Bank Account Amount: " + amount);BankAccountProtected[] bankAccts = new BankAccountProtected[2];bankAccts[0] = new SavingsAccount();bankAccts[1] = new CheckingAccount();foreach (BankAccountProtected acct in bankAccts){// call public method, which invokes protected virtual methodsacct.CloseAccount();}BankAccountExternal BankAcctExt = new BankAccountExternal();// call a public methodamount = BankAcctExt.GetAmount();Console.WriteLine("External Bank Account Amount: " + amount);}}
Comments
Post a Comment