Advertisement
k_vychodilova

Ilogger a ConsoleLogger test 2

Jun 29th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace @interface
  8. {
  9.     interface ILogger
  10.         {
  11.             void Log(string text);
  12.         }
  13.         class ConsoleLogger:ILogger
  14.         {
  15.             public void Log(string text)
  16.             {
  17.                 Console.WriteLine(text);
  18.  
  19.             }
  20.  
  21.         }
  22.  
  23.     //tady bude vytvořeno ucetbase, ucet poplatky apod
  24.     class UcetBase
  25.     {
  26.         public ILogger logger = null;
  27.         public decimal Zustatek { get; set;}
  28.         public UcetBase(ILogger logger)
  29.         {
  30.             this.logger = logger;
  31.             Zustatek = 1000;
  32.         }
  33.         public void Vyber(decimal castka)
  34.         {
  35.             if (castka > Zustatek)
  36.             {
  37.                 logger.Log("error");
  38.             }
  39.         }
  40.  
  41.  
  42. //nemam tu LoggerA a Logger B
  43.     }
  44.     class Banka
  45.  
  46.     {
  47.         private List<UcetBase> ucty = null;
  48.  
  49.         public Banka()
  50.  
  51.         {
  52.  
  53.             ucty = new List<UcetBase>();
  54.  
  55.         }
  56.  
  57.         public void Pridej(UcetBase ucet)
  58.  
  59.         {
  60.  
  61.             LoggerA.Log("pridani uctu"); // pridani uctu
  62.  
  63.             ucty.Add(ucet);
  64.  
  65.         }
  66.  
  67.         public void VypisTypy()
  68.  
  69.         {
  70.  
  71.             LoggerB.Instance.Log("vypis uctu"); // vypis uctu
  72.  
  73.             foreach (UcetBase ucet in ucty)
  74.  
  75.             {
  76.  
  77.                 Console.WriteLine($"{ucet.VratTyp()}, majitel: {ucet.Majitel}");
  78.  
  79.             }
  80.  
  81.         }
  82.  
  83.     }
  84.     class Program
  85.     {
  86.        
  87.         static void Main(string[] args)
  88.         {
  89.             ConsoleLogger logger = new ConsoleLogger();
  90.             UcetBase prvni = new UcetBase(logger);
  91.             prvni.Vyber(100);
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement