Advertisement
aslen

Untitled

Dec 16th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 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 Rusanov2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             GetDefaultDate defaultDate = new GetDefaultDate();
  14.             FormatDate formatDate = new FormatDate();
  15.             SuperFormat superFormatted = new SuperFormat();
  16.  
  17.             DateResolver nowDate = new DateResolver(defaultDate, formatDate);
  18.             DateResolver superDate = new DateResolver(defaultDate, superFormatted);
  19.  
  20.             Console.WriteLine(nowDate.GetDateFormatted());
  21.             Console.WriteLine(superDate.GetDateFormatted());
  22.  
  23.  
  24.         }
  25.     }
  26.     class DateResolver
  27.     {
  28.         private IGetDate currentDate;
  29.         private IFormattedDate formatDate;
  30.  
  31.         public DateResolver(IGetDate defaultDate, IFormattedDate formatDate)
  32.         {
  33.             this.currentDate = defaultDate;
  34.             this.formatDate = formatDate;
  35.         }
  36.         public string GetDateFormatted()
  37.         {
  38.             return formatDate.FormattedDate(currentDate.GettingDate());
  39.         }
  40.     }
  41.  
  42.     interface IGetDate
  43.     {
  44.         DateTime GettingDate();
  45.     }
  46.     class GetDefaultDate : IGetDate
  47.     {
  48.         public DateTime GettingDate()
  49.         {
  50.             return DateTime.Now;
  51.         }
  52.     }
  53.  
  54.     interface IFormattedDate
  55.     {
  56.         string FormattedDate(DateTime date);
  57.     }
  58.     class FormatDate : IFormattedDate
  59.     {
  60.         public string FormattedDate(DateTime date)
  61.         {
  62.             return date.ToString("dd:MM:yyyy");
  63.         }
  64.     }
  65.     class SuperFormat : IFormattedDate
  66.     {
  67.  
  68.         public string FormattedDate(DateTime date)
  69.         {
  70.             return date.ToString("dd/MM/yyyy HH:mm:ss");
  71.         }
  72.     }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement