public static void Main()
var option = new Option();
var factory = new OrderingServiceFactory();
var pageService = factory.GetOrderingService(page);
var optionService = factory.GetOrderingService(option);
Console.WriteLine(pageService.IsDisplayedInRandomOrder(page));
Console.WriteLine(optionService.IsDisplayedInRandomOrder(option));
Console.WriteLine("Hello World");
public interface IOrderingService
bool IsDisplayedInRandomOrder(ICanBeOrdered entity);
public interface ICanBeOrdered
public class Page : ICanBeOrdered
public class Option : ICanBeOrdered
public class OptionOrderingService : OrderingService<Option>
protected override bool IsDisplayedInRandomOrder(Option entity)
public class PageOrderingService : OrderingService<Page>
protected override bool IsDisplayedInRandomOrder(Page entity)
public class OrderingServiceFactory
public IOrderingService GetOrderingService(ICanBeOrdered orderableDestination)
switch (orderableDestination)
return new OptionOrderingService();
return new PageOrderingService();
throw new NotImplementedException($"No implementation found for OrderingService<T> for type: {orderableDestination.GetType()}");
public abstract class OrderingService<T> : IOrderingService where T : ICanBeOrdered
public bool IsDisplayedInRandomOrder(ICanBeOrdered entity)
return this.IsDisplayedInRandomOrder(actual);
throw new NotImplementedException($"No implmentation found for OrderingService<T> for type: {entity.GetType()}");
protected abstract bool IsDisplayedInRandomOrder(T actual);