473,320 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Design Patterns

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
}

}
Jan 13 '07 #1
7 1375
Create an interface that takes the number as input and outputs as a string.
You can then create a factory pattern that serves up the correct class
depending on what you ask the factory. If you want to go full bore with
design patterns, you create an abstract factory that returns the class that
adheres to the interface and call a concrete factory for each type. This is
probably overkill for this example, but will give you great experience in
patterns (and is most "technically" correct).

For examples:
http//:www.dofactory.com

UML is a bit dated for .NET, in some ways, and the design surfaces in team
system have kept up. Do not let this discourage your UML use, as the models
are very similar.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

********************************************
Think outside the box!
********************************************
"sck10" <sc***@online.nospamwrote in message
news:Oi**************@TK2MSFTNGP02.phx.gbl...
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
}

}

Jan 13 '07 #2
Buy, borrow, or steal a copy of Refactoring by Martin Fowler.

http://hanuska.blogspot.com/2006/08/...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
}

}
Jan 13 '07 #3

You can look at my blog for the Simple Factory pattern:
http://sholliday.spaces.live.com/blog/ 12/1/2005

As previously stated, you can create an interface.

IFormatCurrency

2 classes that implement this interface (these are called "concrete
classes")

FixedCurrencyFormatter : IFormatCurrency

PercentCurrencyFormatter : IFormatCurrency

then you create "Factory" that returns a IFormatCurrency

pubic static IFormatCurrency ( string param1 , string param2 , string
param3)
//implement the logic to either return a FixedCurrencyFormatter or a
PercentCurrencyFormatter.
You can also look a the Strategy Pattern
http://www.dofactory.com/Patterns/PatternStrategy.aspx
You would choose the Strategy pattern if you knew your Entity/BusinessObject
had to have one CurrencyFormatter, and if you wanted to change its
CurrencyFormatter at run time. (or compile time, but at run time also).


"sck10" <sc***@online.nospamwrote in message
news:Oi**************@TK2MSFTNGP02.phx.gbl...
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
}

}


Jan 14 '07 #4
Thanks Flinky Wisty Pomm,
"Flinky Wisty Pomm" <Pa********@gmail.comwrote in message
news:11*********************@l53g2000cwa.googlegro ups.com...
Buy, borrow, or steal a copy of Refactoring by Martin Fowler.

http://hanuska.blogspot.com/2006/08/...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
}

}

Jan 14 '07 #5
Thanks Cowboy,

appreciated the help...

sck10
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:13**********************************@microsof t.com...
Create an interface that takes the number as input and outputs as a
string. You can then create a factory pattern that serves up the correct
class depending on what you ask the factory. If you want to go full bore
with design patterns, you create an abstract factory that returns the
class that adheres to the interface and call a concrete factory for each
type. This is probably overkill for this example, but will give you great
experience in patterns (and is most "technically" correct).

For examples:
http//:www.dofactory.com

UML is a bit dated for .NET, in some ways, and the design surfaces in team
system have kept up. Do not let this discourage your UML use, as the
models are very similar.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

********************************************
Think outside the box!
********************************************
"sck10" <sc***@online.nospamwrote in message
news:Oi**************@TK2MSFTNGP02.phx.gbl...
>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
}

}


Jan 14 '07 #6
Thanks for the links sloan,

sck10
"sloan" <sl***@ipass.netwrote in message
news:uw**************@TK2MSFTNGP06.phx.gbl...
>
You can look at my blog for the Simple Factory pattern:
http://sholliday.spaces.live.com/blog/ 12/1/2005

As previously stated, you can create an interface.

IFormatCurrency

2 classes that implement this interface (these are called "concrete
classes")

FixedCurrencyFormatter : IFormatCurrency

PercentCurrencyFormatter : IFormatCurrency

then you create "Factory" that returns a IFormatCurrency

pubic static IFormatCurrency ( string param1 , string param2 , string
param3)
//implement the logic to either return a FixedCurrencyFormatter or a
PercentCurrencyFormatter.
You can also look a the Strategy Pattern
http://www.dofactory.com/Patterns/PatternStrategy.aspx
You would choose the Strategy pattern if you knew your
Entity/BusinessObject
had to have one CurrencyFormatter, and if you wanted to change its
CurrencyFormatter at run time. (or compile time, but at run time also).


"sck10" <sc***@online.nospamwrote in message
news:Oi**************@TK2MSFTNGP02.phx.gbl...
>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
}

}



Jan 15 '07 #7
Thanks for the help Sloan...

sck10
"sloan" <sl***@ipass.netwrote in message
news:uw**************@TK2MSFTNGP06.phx.gbl...
>
You can look at my blog for the Simple Factory pattern:
http://sholliday.spaces.live.com/blog/ 12/1/2005

As previously stated, you can create an interface.

IFormatCurrency

2 classes that implement this interface (these are called "concrete
classes")

FixedCurrencyFormatter : IFormatCurrency

PercentCurrencyFormatter : IFormatCurrency

then you create "Factory" that returns a IFormatCurrency

pubic static IFormatCurrency ( string param1 , string param2 , string
param3)
//implement the logic to either return a FixedCurrencyFormatter or a
PercentCurrencyFormatter.
You can also look a the Strategy Pattern
http://www.dofactory.com/Patterns/PatternStrategy.aspx
You would choose the Strategy pattern if you knew your
Entity/BusinessObject
had to have one CurrencyFormatter, and if you wanted to change its
CurrencyFormatter at run time. (or compile time, but at run time also).


"sck10" <sc***@online.nospamwrote in message
news:Oi**************@TK2MSFTNGP02.phx.gbl...
>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
}

}



Jan 16 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of...
1
by: Jay | last post by:
The GOF text is widely considered the definitive book on the topic. Design Patterns: Elements of Reusable Object-Oriented Softare, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides ...
1
by: Josh28 | last post by:
Hi We are a group of two chaps just out of undergrad, we created a software to automate the use of Design Patterns. We have put it up at Source Forge--http://dpatoolkit.sourceforge.net/ The...
13
by: John Salerno | last post by:
Here are a few I'm considering: Design Patterns Explained : A New Perspective on Object-Oriented Design (2nd Edition) (Software Patterns Series) by Alan Shalloway Design Patterns C# by...
2
by: Carlo Stonebanks | last post by:
I have the infamous GoF Design Patterns boo - it's been sittin gon my shelf for years. I have a huge reading list and find this book a rather dry read and am always putting it off. I have...
22
by: Krivenok Dmitry | last post by:
Hello All! I am trying to implement my own Design Patterns Library. I have read the following documentation about Observer Pattern: 1) Design Patterns by GoF Classic description of Observer....
5
by: Ludwig Wittgenstein | last post by:
Other than the Design Patterns book, which book(s) is/are the best to learn object-oriented software design/architecture from ?
7
by: =?Utf-8?B?bWF2cmlja18xMDE=?= | last post by:
Hi, I would like to know more about design patterns and specifically using C#. Can any one recommend a good book? Thanks
5
by: macca | last post by:
Hi, I'm looking for a good book on PHP design patterns for a OOP beginner - Reccommendations please? Thanks Paul
10
by: vital | last post by:
Hi, I am designing the middle tier of a project. It has 6 classes and microsoft application data access block. The six classes are DBServices, Logger, ProjectServices ... etc. and all these...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.