Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

design pattern for so many conditions c#

class ActionState
{
  public bool Condition1{get;set;}
  public bool Condition2{get;set;}
  public bool Condition3{get;set;}
}

abstract class ActionDispatcher
{
  protected abstract void ExecuteAction1();
  protected abstract void ExecuteAction2();
  protected abstract void ExecuteAction2();

  public void Action1(ActionState state)
  {
    if(state.Condition1 && state.Condition2)
    {
      ExecuteAction1();
    }
  }

  public void Action2(ActionState state)
  {
    if(state.Condition2 && state.Condition3)
    {
      ExecuteAction2();
    }
  }

  public void Action3(ActionState state)
  {
    if(state.Condition1 && state.Condition2 && state.Condition3)
    {
      ExecuteAction3();
    }
  }

  public void AllActions(ActionState state)
  {
    // Execute all actions depending on the state
    Action1(state);
    Action2(state);
    Action3(state);
  }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to take previous record in linq c# 
Csharp :: xml reader attributes 
Csharp :: .net check connection 
Csharp :: netmath 
Csharp :: c# generate random key with specified length 
Csharp :: version string c# 
Csharp :: what is vector3.one c# 
Csharp :: unity enable hdr picker 
Csharp :: stack iterator c# 
Csharp :: delegates in c# 
Csharp :: how to set an expiry date on a program 
Csharp :: how to get variable value in properties file in inspector unity 
Csharp :: linq get values is not in other table 
Csharp :: c# restore form 
Csharp :: c# crud observablecollection -mvvm 
Csharp :: C# Blocks without statements 
Csharp :: creating weighted graph in c# 
Csharp :: Stop Unity Wait Time with Button 
Csharp :: blazor OnInitializedAsync Unhandled exception rendering component: Cannot wait on monitors on this runtime. 
Csharp :: asp.net unregister client script 
Csharp :: All and Any linq c# examlpe replace 
Csharp :: how to create more accurate searching c# 
Csharp :: Handle all AggregateExceptions when using Task.Whenall() async 
Csharp :: c# textbox tab column 
Csharp :: process which converts natural sugar into alcohol by yeast 
Csharp :: six simple machines labeled 
Csharp :: add numbers c# 
Csharp :: regex ip rage detect c# 
Csharp :: c# hashset 
Csharp :: get sites ip in C# 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =