Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
3
Answers
Strategy Pattern VS Static Class
Mohammed Mostafa
13y
2.1k
1
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
[
^
]
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
ADO.Net
Threading Problem