Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. public interface IDatastore
  2. {
  3.     string GetSomeData(string key);
  4. }
  5.  
  6. public class FileDatastore : IDatastore
  7. {
  8.     public string GetSomeData(string key)
  9.     {
  10.         return File.ReadAllText($@"C:\foo\bar\{key}.txt");
  11.     }
  12. }
  13.  
  14. public class WebDatastore : IDatastore
  15. {
  16.     public string GetSomeData(string key)
  17.     {
  18.         return new WebClient().DownloadString($"http://foo.com/bar/{key}");
  19.     }
  20. }
  21.  
  22. public class SomeBusinessLogicClass
  23. {
  24.     private IDatastore _datastore;
  25.    
  26.     public SomeBusinessLogicClass(IDatastore datastore)
  27.     {
  28.         _datastore = datastore;
  29.     }
  30.  
  31.     public void DoStuff()
  32.     {
  33.         var value = _datastore.GetSomeData("foo");
  34.         Console.WriteLine(value);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement