Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace @interface
- {
- interface ILogger
- {
- void Log(string text);
- }
- class ConsoleLogger:ILogger
- {
- public void Log(string text)
- {
- Console.WriteLine(text);
- }
- }
- //tady bude vytvořeno ucetbase, ucet poplatky apod
- class UcetBase
- {
- public ILogger logger = null;
- public decimal Zustatek { get; set;}
- public UcetBase(ILogger logger)
- {
- this.logger = logger;
- Zustatek = 1000;
- }
- public void Vyber(decimal castka)
- {
- if (castka > Zustatek)
- {
- logger.Log("error");
- }
- }
- //nemam tu LoggerA a Logger B
- }
- class Banka
- {
- private List<UcetBase> ucty = null;
- public Banka()
- {
- ucty = new List<UcetBase>();
- }
- public void Pridej(UcetBase ucet)
- {
- LoggerA.Log("pridani uctu"); // pridani uctu
- ucty.Add(ucet);
- }
- public void VypisTypy()
- {
- LoggerB.Instance.Log("vypis uctu"); // vypis uctu
- foreach (UcetBase ucet in ucty)
- {
- Console.WriteLine($"{ucet.VratTyp()}, majitel: {ucet.Majitel}");
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- ConsoleLogger logger = new ConsoleLogger();
- UcetBase prvni = new UcetBase(logger);
- prvni.Vyber(100);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement