Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
Strategy Pattern VS Static Class
Mohammed Mostafa
Oct 7 2011 11:06 AM
2.1k
Reply
need someone professional help me get the difference beteen
first :
static
class
SimpleMathOperations
{
public
static
double
add(
double
a,
double
b) {
return
a + b; }
public
static
double
subtract(
double
a,
double
b) {
return
a - b; }
public
static
double
multiply(
double
a,
double
b) {
return
a * b; }
public
static
double
divide(
double
a,
double
b) {
return
a / b; } }
second : Implementing the strategy pattern
public
interface
IMathOperation {
double
PerformOperation(
double
A,
double
B); }
//
ADD -----------------------------------------------
class
AddOperation: IMathOperation
{
#region
IMathOperation Members
public
double
PerformOperation(
double
A,
double
B)
{
return
A + B; }
#endregion
}
//
Subtract -----------------------------------------------
class
SubtractOperation: IMathOperation
{
#region
IMathOperation Members
public
double
PerformOperation(
double
A,
double
B)
{
return
A - B; }
#endregion
}
//
MULTILPY -----------------------------------------------
class
MultiplyOperation: IMathOperation
{
#region
IMathOperation Members
public
double
PerformOperation(
double
A,
double
B) {
return
A * B; }
#endregion
}
//
DIVIDE -----------------------------------------------
class
DivideOperation: IMathOperation
{
#region
IMathOperation Members
public
double
PerformOperation(
double
A,
double
B) {
return
A/B; }
#endregion
}
I quoted strategy pattern from this website
http://www.c-sharpcorner.com/UploadFile/rmcochran/strategyPattern08072006095804AM/strategyPattern.aspx
[
^
]
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
ADO.Net
Threading Problem