2075 / C# / Шаблони / Замісник (Proxy)
Те саме, що Adapter, але з логуванням
interface INeedInterface { void Send(); } class DontTouchMe { public void SendLeter() { } } class Proxy : INeedInterface { DontTouchMe obj; DateTime t; public Proxy(DontTouchMe obj) { t = DateTime.Now; File.AppendAllText("Log.txt", "Create proxy " + t.ToLongTimeString() + ":" + t.Millisecond + "\n"); this.obj = obj; } public void Send() { t = DateTime.Now; File.AppendAllText("Log.txt", "Send Leter " + t.ToLongTimeString() + ":" + t.Millisecond + "\n"); obj.SendLeter(); } } static void Main(string[] args) { Proxy proxy = new Proxy(new DontTouchMe()); Console.WriteLine("Press any key"); Console.ReadKey(); proxy.Send(); Console.WriteLine("Press any key"); Console.ReadKey(); proxy.Send(); Console.WriteLine("Press any key"); Console.ReadKey(); proxy.Send(); Console.ReadKey(); }
Create proxy 0:38:13:981
Send Leter 0:38:15:230
Send Leter 0:38:16:444
Send Leter 0:38:17:563
Send Leter 0:38:15:230
Send Leter 0:38:16:444
Send Leter 0:38:17:563