Advertisement
csaki

Adapter pattern example 2

Mar 6th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace AdapterExample
  7. {
  8.     abstract class Flashlight
  9.     {
  10.         public abstract void Light();
  11.     }
  12.  
  13.     abstract class Mobile
  14.     {
  15.         public abstract void Call(string person);
  16.     }
  17.  
  18.     class Mobile2Flashlight : Flashlight
  19.     {
  20.         Mobile mobile;
  21.         public Mobile2Flashlight(Mobile m)
  22.         {
  23.             mobile = m;
  24.         }
  25.  
  26.         public override void Light()
  27.         {
  28.             mobile.Call(null);
  29.         }
  30.     }
  31.  
  32.     class iPhone : Mobile
  33.     {
  34.         public override void Call(string person)
  35.         {
  36.             Console.WriteLine("I called {0}!", person);
  37.         }
  38.     }
  39.  
  40.     class Lighter : Flashlight
  41.     {
  42.         public override void Light()
  43.         {
  44.             Console.WriteLine("I lighted with lighter");
  45.         }
  46.     }
  47.  
  48.     class Program
  49.     {
  50.         static void Main(string[] args)
  51.         {
  52.  
  53.             Console.ReadLine();
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement