Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Composite.Pattern
- {
- public interface BankAccount
- {
- void Add(BankAccount account);
- void Remove(BankAccount account);
- BankAccount Get(BankAccount account);
- int GetMoney();
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Composite.Pattern
- {
- public class Bank : BankAccount {
- private List<BankAccount> listOfAccounts = new List<BankAccount>();
- public void Add(BankAccount account)
- {
- this.listOfAccounts.Add(account);
- }
- public void Remove(BankAccount account)
- {
- this.listOfAccounts.Remove(account);
- }
- public BankAccount Get(BankAccount account) {
- return this.listOfAccounts.Find(delegate(BankAccount acc) { return acc == account; });
- }
- public int GetMoney()
- {
- int sum = 0;
- foreach (BankAccount acc in listOfAccounts) {
- sum += acc.GetMoney();
- }
- return sum;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Composite.Pattern
- {
- public class SpecifyAccount : BankAccount {
- private int cash;
- public void InsertMoney(int cash)
- {
- this.cash += cash;
- }
- public int GetMoney()
- {
- return this.cash;
- }
- public void Add(BankAccount account)
- {
- throw new NotImplementedException();
- }
- public void Remove(BankAccount account)
- {
- throw new NotImplementedException();
- }
- public BankAccount Get(BankAccount account)
- {
- throw new NotImplementedException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment