close
This tutorial is about adapter pattern, which is my thoghts after watching the tutorial created by Christopher Okhravi.
ITarget portion:
1: namespace AdapterPattern
2: {3: interface ITarget
4: {5: void Request();
6: } 7: }Adaptee portion:
1: namespace AdapterPattern
2: {3: class Adaptee
4: {5: public void specificRequest()
6: {7: Console.WriteLine("The ouptut is 220 volatge.");
8: } 9: } 10: }Adapter portion:
1: namespace AdapterPattern
2: {3: class Adapter:ITarget
4: {5: private Adaptee adaptee;
6: public Adapter(Adaptee _adaptee)
7: {8: this.adaptee = _adaptee;
9: }10: public void Request()
11: {12: Console.WriteLine("The input is 110 voltage and being leveled up...");
13: this.adaptee.specificRequest();
14: } 15: } 16: }Console portion:
1: class Program
2: {3: static void Main(string[] args)
4: {5: Adaptee volt220 = new Adaptee();
6: ITarget volt110 = new Adapter(volt220);
7: volt110.Request(); 8: Console.ReadKey(); 9: } 10: }
全站熱搜





留言列表
