using System.Collections.Generic;
public static void Main()
var productService = new ProductService();
productService.GetProducts();
Console.WriteLine("------");
var cacheProductService = new CacheProductService(new ProductService());
cacheProductService.GetProducts();
Console.WriteLine("------");
var logProductService = new LogProductService(new CacheProductService(new ProductService()));
logProductService.GetProducts();
public interface IProductService
List<Product> GetProducts();
public class ProductService : IProductService
public List<Product> GetProducts()
Console.WriteLine("Products fetched");
return Enumerable.Empty<Product>().ToList();
public abstract class ProductServiceDecorator : IProductService
protected IProductService ProductService { get; }
protected ProductServiceDecorator(IProductService productService)
ProductService = productService;
public abstract List<Product> GetProducts();
public class CacheProductService : ProductServiceDecorator
public CacheProductService(IProductService productService) : base(productService)
public override List<Product> GetProducts()
Console.WriteLine("Products cached");
return ProductService.GetProducts();
public class LogProductService : ProductServiceDecorator
public LogProductService(IProductService productService) : base(productService)
public override List<Product> GetProducts()
Console.WriteLine("Request logged");
return ProductService.GetProducts();