using System;
using System.Collections.Generic;
public interface INotification
{
void SendEmail(string to, string subject, string body);
void SendSms(string phone, string message);
}
public class OrderProcessor
{
private EmailNotification _emailNotifier = new EmailNotification();
private FileLogger _logger = new FileLogger();
public void Process(Order order, string customerEmail, string customerPhone)
{
// Логирование начала обработки
_logger.Log($"Processing order {order.Id}");
// Расчёт скидки
decimal discount = 0;
if (order.Total > 100) discount = order.Total * 0.1m;
else if (order.Total > 50) discount = order.Total * 0.05m;
order.Total -= discount;
// Отправка уведомлений
_emailNotifier.SendEmail(customerEmail, "Order processed", $"Total: {order.Total}");
_emailNotifier.SendSms(customerPhone, $"Order {order.Id} total: {order.Total}");
// Логирование завершения
_logger.Log($"Finished processing order {order.Id}");
}
}
public class EmailNotification : INotification
{
public void SendEmail(string to, string subject, string body)
{
Console.WriteLine($"Sending email to {to}: {subject} - {body}");
}
public void SendSms(string phone, string message)
{
throw new NotImplementedException("EmailNotification cannot send SMS");
}
}
public class FileLogger
{
public void Log(string message)
{
// Симуляция записи в файл
Console.WriteLine($"[LOG] {message}");
}
}
public class DiscountCalculator
{
public virtual decimal Calculate(Order order)
{
return order.Total * 0.05m;
}
}
public class SpecialDiscountCalculator : DiscountCalculator
{
public override decimal Calculate(Order order)
{
if (order.Total < 100)
throw new InvalidOperationException("Special discount only for orders over 100");
return order.Total * 0.2m;
}
}
public class Order
{
public int Id { get; set; }
public decimal Total { get; set; }
}