Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 25th, 2013  |  syntax: C#  |  size: 1.47 KB  |  views: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     public sealed class SomeExternalClassWithoutInterface
  2.     {
  3.         private readonly string _someValue;
  4.  
  5.         public SomeExternalClassWithoutInterface(string someConstructorValue)
  6.         {
  7.             _someValue = someConstructorValue;
  8.         }
  9.         public string Method1()
  10.         {
  11.             return _someValue;
  12.         }
  13.  
  14.         public int Method2()
  15.         {
  16.             return _someValue.Length;
  17.         }
  18.     }
  19.  
  20.     public class ExternalClassAdapter : IExternalClassAdapter
  21.     {
  22.         private readonly SomeExternalClassWithoutInterface _someExternalClassWithoutInterface;
  23.  
  24.         // DI implementation, this is not neccesary
  25.         public ExternalClassAdapter(SomeExternalClassWithoutInterface someExternalClassWithoutInterface)
  26.         {
  27.             _someExternalClassWithoutInterface = someExternalClassWithoutInterface;
  28.         }
  29.  
  30.         // Constructor Without Depedency Injection, this is not preferable.
  31.         public ExternalClassAdapter(string someValue)
  32.         {
  33.             _someExternalClassWithoutInterface = new SomeExternalClassWithoutInterface(someValue);
  34.         }
  35.  
  36.  
  37.         public string Method1()
  38.         {
  39.             return _someExternalClassWithoutInterface.Method1();
  40.         }
  41.  
  42.         public int Method2()
  43.         {
  44.             return _someExternalClassWithoutInterface.Method2();
  45.         }
  46.     }
  47.  
  48.     public interface IExternalClassAdapter
  49.     {
  50.         string Method1();
  51.         int Method2();
  52.     }
clone this paste RAW Paste Data