Introduction
Today, in this article let's play around with one of the interesting and most useful concept of design pattern, which will be hosted on web app.
Question: What is Strategy Pattern?
In simple terms "The algorithmic code is implemented in various specific classes and can be used when required. The algorithmic code differs from one class to another".
I think we are now good to go to implement this wonderful concept.
Step 1: The complete code of Default.aspx looks like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="StatergyDesignPatternApplication._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1 style="text-align: center; font-family: Verdana; font-size: large; color: Maroon">
Strategy Pattern - Design Patterns</h1>
<center>
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Please Enter First Number" Font-Size="Small"
Font-Bold="true" Font-Italic="true" Font-Names="Verdana"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Please Enter Second Number" Font-Size="Small"
Font-Bold="true" Font-Italic="true" Font-Names="Verdana"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button1" runat="server" Text="Addition" Width="165px" Font-Names="Verdana"
BackColor="Orange" OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button2" runat="server" Text="Subtraction" Width="165px" Font-Names="Verdana"
BackColor="Orange" OnClick="Button2_Click" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button3" runat="server" Text="Multiplication" Width="165px" Font-Names="Verdana"
BackColor="Orange" OnClick="Button3_Click" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button4" runat="server" Text="Division" Width="165px" Font-Names="Verdana"
BackColor="Orange" OnClick="Button4_Click" />
</td>
</tr>
</table>
<table>
<tr>
<td colspan="2">
<asp:Label ID="lblResult" runat="server" Font-Names="Verdana" ForeColor="Brown"></asp:Label>
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>




Join the conversation! Your thoughts help the community grow.