// adapter pattern example using System; interface account { void deposit(int x); void withdraw(int x); int inquiry(); } // assume there are several concrete account classes like savings, checking... class iraaccount // adaptee class - assume written by someone else { private int balance; public readonly string name; // readonly means can only assign once public iraaccount(string n, int x) {balance=x; name=n;} public int transaction(int amt) { balance +=amt; // a negative amt will withdraw return balance; } // ... } class accAdapter : account // adopts an iraaccount to account interface { private iraaccount iac; // object to be adopted public accAdapter(iraaccount a) {iac = a;} // constructor instantiates // methods consistent with account interface: public void deposit(int y) { iac.transaction(y); } public void withdraw(int y) { iac.transaction(-y); } public int inquiry() { return iac.transaction(0); } } // accAdapter //// usage public class adapterp { public static void Main() { iraaccount yourira = new iraaccount("you",5000); // now I want to use this iraaccount like an "account" account a1 = new accAdapter(yourira); a1.withdraw(1000); a1.deposit(2000); Console.WriteLine("your balance is "+a1.inquiry()); } }