Advertisement
T-D-K

Untitled

Feb 12th, 2018
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. interface IRemindersEmptyCalculator{
  2.     bool IsRemindersEmpty(List<Remider> reminders);
  3. }
  4.  
  5. class RemindersEmptyCalculatorFactory{
  6.     readonly Context context;
  7.     readonly DefaultIsRemindersEmptyCalculator defaultIsRemindersEmptyCalculator
  8.     RemindersEmptyCalculatorFactory(Context context){
  9.         this.context = context;
  10.     }
  11.    
  12.     public IRemindersEmptyCalculator GetCalculator(){
  13.         switch context.State{
  14.             case Web:
  15.             break;
  16.             case Local:
  17.             break;
  18.             default:
  19.             return new DefaultIsRemindersEmptyCalculator();
  20.     }
  21. }
  22.  
  23. public class DefaultIsRemindersEmptyCalculator:IRemindersEmptyCalculator
  24. {
  25.     private static readonly Lazy<DefaultIsRemindersEmptyCalculator> _instance =
  26.         new Lazy<DefaultIsRemindersEmptyCalculator>(() => new DefaultIsRemindersEmptyCalculator());
  27.  
  28.     public static DefaultIsRemindersEmptyCalculator Instance => _instance.Value;
  29.  
  30.     private DefaultIsRemindersEmptyCalculator() {}
  31.    
  32.     public bool IsRemindersEmpty(List<Remider> remiders){
  33.         return reminders.Count > 0 ? true : false;
  34.     }
  35. }
  36.  
  37. static void Main(List<Remider> reminders){
  38.     Context = GetCurrentContext();
  39.     RemindersEmptyCalculatorFactory factory = new RemindersEmptyCalculatorFactory(context);
  40.     IRemindersEmptyCalculator isRemindersEmptyCalculator = factory.GetCalcylator();
  41.     bool isRemindersEmpty = isRemindersEmptyCalculator.IsRemindersEmpty(reminders);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement