Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multiple return points - is it OK practice?
Message
De
01/02/2013 18:20:24
 
 
À
01/02/2013 18:11:44
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01564936
Message ID:
01564979
Vues:
48
Look at Chain of Responsibility pattern. All those flags and ifs are an anti-pattern.

>Here's how we avoid nested if's
>
>
>public bool ErrorChecker()
>{
>   bool OKToProceed = true;
>  if (error1)
>  {
>      OKToProceed = false;
>      Logerror("1");  
>}
>  if(OKTOProceed)
>  {
>      if (error2)
>      {
>        OKToProceed = false;
>         Logerror("2");         
>    }
>  }
>  if(OKTOProceed)
>  {
>     if (error3)
>    {
>       OKToProceed = false;
>        Logerror("3");    
>    }
> 
>  // etc, etc
>   } 
>return OKToProceed;
>}
>
>
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform