Facebook
From Ivory Peccary, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 201
  1. interface IDbContext
  2. {
  3.   void Add(...);
  4. }
  5.  
  6. class MSSQLDb : IDbContext
  7. {
  8.  
  9.   public void Add(...)
  10.   {
  11.     // Saving to MSSQL...
  12.   }
  13. }
  14.  
  15. class BrowserDb : IDbContext
  16. {
  17.  
  18.   public void Add(...)
  19.   {
  20.     // Saving to cookies...
  21.   }
  22. }
  23.  
  24. interface ICart
  25. {
  26.   void Add(Product product);
  27.   void Checkout();
  28. }
  29.  
  30. class Cart : ICart
  31. {
  32.   IDbContext storage = new MSSQLDb();
  33.   public void Add(Product product)
  34.   {
  35.     storage.Add(product);
  36.   }
  37.  
  38.   public void Checkout()
  39.   {
  40.    
  41.   }
  42.  
  43. }
  44.  
  45. class CartProxy : ICart
  46. {
  47.   IDbContext storage = new BrowserDb();
  48.   public void Add(Product product)
  49.   {
  50.     storage.Add(product);
  51.   }
  52.  
  53.   public void Checkout()
  54.   {
  55.     ICart cart = new Cart();
  56.    
  57.     cart.Add();
  58.    
  59.   }
  60. }