daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest May 17th, 2018 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. namespace NikitaTest
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             ASupplier first = new SupplierFirst();
  10.             ASupplier second = new SupplierSecond();
  11.  
  12.             Consumer cons = new Consumer(first, second);
  13.  
  14.             cons.Notify();
  15.  
  16.             Console.ReadLine();
  17.         }
  18.     }
  19.  
  20.     public abstract class AData
  21.     {
  22.         public abstract void Process();
  23.     }
  24.  
  25.     public class Consumer
  26.     {
  27.         readonly ASupplier[] _suppliers = new ASupplier[2];
  28.  
  29.         public Consumer(ASupplier first, ASupplier second)
  30.         {
  31.             _suppliers[0] = first;
  32.             _suppliers[1] = second;
  33.         }
  34.  
  35.         public void Notify()
  36.         {
  37.             foreach (ASupplier supplier in _suppliers)
  38.             {
  39.                 AData dat = supplier.Invoke();
  40.                 dat.Process();
  41.             }
  42.         }
  43.     }
  44.  
  45.     public abstract class ASupplier
  46.     {
  47.         public abstract AData Invoke();
  48.     }
  49.  
  50.     public class SupplierFirst : ASupplier
  51.     {
  52.         public class DataFirst : AData
  53.         {
  54.             public override void Process()
  55.             {
  56.                 Console.WriteLine("First supplier data processed.");
  57.             }
  58.         }
  59.  
  60.  
  61.         public override AData Invoke() => new DataFirst();
  62.     }
  63.  
  64.     public class SupplierSecond : ASupplier
  65.     {
  66.         private int _count;
  67.         public class DataSecond : AData
  68.         {
  69.             public override void Process()
  70.             {
  71.                 Console.WriteLine("Second supplier data processed.");
  72.             }
  73.         }
  74.  
  75.         public override AData Invoke() => new DataSecond();
  76.     }
  77. }
RAW Paste Data
Top