Re: Design Patterns

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Buy, borrow, or steal a copy of Refactoring by Martin Fowler.

http://hanuska.blogspot.com/2006/08/swich-statement-code-smell-and.html
has some info on refactoring from a switch to a polymorphic dispatch,
but the Refactoring book should be your first port of call for things
like this.

sck10 wrote:

Hello,

I just started reading about Design Patterns and UML Class Diagrams on the
web. Anyway, I have a method that I use to format currency given certain
parameters that are supplied from the dataset from SQL Server. I was going
to create another one for Fixed, Percent ect. I know I could create a
switch statement to do this, but wanted to try to use UML as a learning
process.

So I'm trying to figure out how to break up the simple method below to do
this. Any suggestions or references would be appreciated.

sck10


public class StringFormat
{
public string NumberFormater(
object CompareValue, string CompareToValue,
object FormatValue,
string StartReturn, string EndReturn)
{
string strCompareValue = Convert.ToString(CompareValue);
double dblFormatValue;
string strFormatValue;

if(strCompareValue == CompareToValue)
{
dblFormatValue = Convert.ToDouble(FormatValue);
return StartReturn + string.Format("{0:C0}", FormatValue) + EndReturn;
}
else
{
return string.Format("{0:C0}", FormatValue);
} // end if
}

}

.



Relevant Pages

  • Suggestions for decoupling units?
    ... It made sense to put all the string stuff in a strings unit, ... in a files unit, etc. ... So last evening I started refactoring my app to eliminate unit ... I'm presently defining decoupling, and a decoupled code unit as: ...
    (alt.comp.lang.borland-delphi)
  • Re: Design Patterns
    ... but the Refactoring book should be your first port of call for things ... switch statement to do this, but wanted to try to use UML as a learning ... object CompareValue, string CompareToValue, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: [QUIZ] Dice Roller (#61) ([SOLUTION])
    ... string. ... not been merciless enough when refactoring. ... a comment about one of the parse regexps and a comment in the tests about Fixnum and class methods. ...
    (comp.lang.ruby)
  • Re: Refactoring into ravioli code
    ... public String[] matchNamesThatStartWith (String matchMe) { ... Readability over overly merciless refactoring every time ...
    (comp.object)
  • Refactoring into ravioli code
    ... WikiPedia would seem to disagree but I would see ravioli as an example ... public String[] matchNamesThatStartWith { ... iterates the list calling a test method implemented in specific ... Readability over overly merciless refactoring every time ...
    (comp.object)