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 Rusanov2
- {
- class Program
- {
- static void Main(string[] args)
- {
- GetDefaultDate defaultDate = new GetDefaultDate();
- FormatDate formatDate = new FormatDate();
- SuperFormat superFormatted = new SuperFormat();
- DateResolver nowDate = new DateResolver(defaultDate, formatDate);
- DateResolver superDate = new DateResolver(defaultDate, superFormatted);
- Console.WriteLine(nowDate.GetDateFormatted());
- Console.WriteLine(superDate.GetDateFormatted());
- }
- }
- class DateResolver
- {
- private IGetDate currentDate;
- private IFormattedDate formatDate;
- public DateResolver(IGetDate defaultDate, IFormattedDate formatDate)
- {
- this.currentDate = defaultDate;
- this.formatDate = formatDate;
- }
- public string GetDateFormatted()
- {
- return formatDate.FormattedDate(currentDate.GettingDate());
- }
- }
- interface IGetDate
- {
- DateTime GettingDate();
- }
- class GetDefaultDate : IGetDate
- {
- public DateTime GettingDate()
- {
- return DateTime.Now;
- }
- }
- interface IFormattedDate
- {
- string FormattedDate(DateTime date);
- }
- class FormatDate : IFormattedDate
- {
- public string FormattedDate(DateTime date)
- {
- return date.ToString("dd:MM:yyyy");
- }
- }
- class SuperFormat : IFormattedDate
- {
- public string FormattedDate(DateTime date)
- {
- return date.ToString("dd/MM/yyyy HH:mm:ss");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement