close

This tutorial is about adapter pattern, which is my thoghts after watching the tutorial created by Christopher Okhravi.

image

ITarget portion:

image

   1: namespace AdapterPattern
   2: {
   3:     interface ITarget
   4:     {
   5:         void Request();
   6:     }
   7: }

Adaptee portion:

image

   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:

image

   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: }

 

image

arrow
arrow
    全站熱搜

    me1237guy 發表在 痞客邦 留言(0) 人氣()