Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best way to re-factor
Message
De
14/02/2013 12:46:20
John Baird
Coatesville, Pennsylvanie, États-Unis
 
 
À
14/02/2013 12:11:55
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:
01565967
Message ID:
01566035
Vues:
65
>>>>>I changed the top part (up to OK to close drawer) into a separate method. The question now is - can I re-use this piece somehow in two places?
>>>>>
>>>>>
>>>>>String currentOperator, currentSalespoint, closeOperator, closeSalespoint, cDetails;
>>>>>                        currentOperator = GetParameterValue(parameters, "tcOperator");
>>>>>                        currentSalespoint = GetParameterValue(parameters, "tcSalespoint");
>>>>>                        cDetails = GetParameterValue(parameters, "tcDetails");
>>>>>                        closeOperator = cDetails.ParseStringFromSqml("CLOSE_OP");
>>>>>                        if (String.IsNullOrWhiteSpace(closeOperator))
>>>>>                            closeOperator = currentOperator;
>>>>>                        closeSalespoint = cDetails.ParseStringFromSqml("CLOSE_SP");
>>>>>                        if (String.IsNullOrWhiteSpace(closeSalespoint))
>>>>>                            closeSalespoint = currentSalespoint;
>>>>>                        DateTime startTime, endTime;
>>>>>                        startTime = cDetails.ParseDateTimeFromSqml("START_TIME");
>>>>>                        endTime = cDetails.ParseDateTimeFromSqml("END_TIME");
>>>>>
>>>>>
>>>>>?
>>>>>
>>>>>I guess I can pass back all parameters by reference, but is it a good solution?
>>>>>
>>>>It isn't so difficult to see that that method needs as
>>>>In Parameters : parameters
>>>>Out Parameters: startTime, endTime
>>>>
>>>>
>>>>void TheMethod( type of parameters, out DateTime startTime, out DateTime endTime)
>>>>{ 
>>>>   // the code 
>>>>}
>>>>
>>>
>>>It actually also needed closeSalespoint and closeOperator. I sent both as out parameters but I was thinking I may create the above as a class instead with these properties. Do you think it will be a better solution or 4 out parameters is not bad?
>>
>>
>>IMNHO, I never use out parameters unless forced to by the .net framework. A method should have one entry, one exit and perform one function. I always pass/return either custom classes or tuples. Much more professional than spaghetti code with multiple entries, exits, and out parameters.
>
>Are we going to re-open that discussion :-}
>Do you really think that the type of pattern used by, for example, Int.TryParse() does not have uses ?

No, it has its place, I guess, but it could just as easily have returned an object with 2 properties. Not looking to restart a lengthy discussion on style. It is just my personal opinion and practice.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform