diff options
| author | mo.khan <mo.khan@a0a4a051-f042-0410-9e78-9fae330bdb64> | 2008-01-05 07:16:52 +0000 |
|---|---|---|
| committer | mo.khan <mo.khan@a0a4a051-f042-0410-9e78-9fae330bdb64> | 2008-01-05 07:16:52 +0000 |
| commit | 8c137f229c36a777ead5cacb3350cb8692646292 (patch) | |
| tree | 92876c5da0ffd17767e38f94a44415ac27a3c73e /DesignPatterns/src/app/DesignPatterns.Strategy | |
| parent | cbdf42a6427eef7849d1ab7731f9185b410431d3 (diff) | |
git-svn-id: http://mokhan.googlecode.com/svn/trunk@9 a0a4a051-f042-0410-9e78-9fae330bdb64
Diffstat (limited to 'DesignPatterns/src/app/DesignPatterns.Strategy')
13 files changed, 273 insertions, 0 deletions
diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/Axe.cs b/DesignPatterns/src/app/DesignPatterns.Strategy/Axe.cs new file mode 100644 index 0000000..ec6dcfb --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/Axe.cs @@ -0,0 +1,14 @@ +/*
+ * Created by:
+ * Created: Monday, July 02, 2007
+ */
+
+using System;
+
+namespace DesignPatterns.Strategy {
+ public class Axe : IWeapon {
+ public void UseWeapon( ) {
+ Console.Out.WriteLine( "Lunge with Axe" );
+ }
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/BowAndArrow.cs b/DesignPatterns/src/app/DesignPatterns.Strategy/BowAndArrow.cs new file mode 100644 index 0000000..760ec47 --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/BowAndArrow.cs @@ -0,0 +1,14 @@ +/*
+ * Created by:
+ * Created: Monday, July 02, 2007
+ */
+
+using System;
+
+namespace DesignPatterns.Strategy {
+ public class BowAndArrow : IWeapon {
+ public void UseWeapon( ) {
+ Console.Out.WriteLine( "Fire bow and arrow!" );
+ }
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/Character.cs b/DesignPatterns/src/app/DesignPatterns.Strategy/Character.cs new file mode 100644 index 0000000..7b2243c --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/Character.cs @@ -0,0 +1,37 @@ +/*
+ * Created by:
+ * Created: Monday, July 02, 2007
+ */
+
+namespace DesignPatterns.Strategy {
+ public abstract class Character {
+ #region Constructors
+
+ public Character( IWeapon weapon ) {
+ _weapon = weapon;
+ }
+
+ #endregion
+
+ #region Public Properties
+
+ public IWeapon Weapon {
+ get { return _weapon; }
+ set { _weapon = value; }
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ public abstract void Fight( );
+
+ #endregion
+
+ #region Private Fields
+
+ private IWeapon _weapon;
+
+ #endregion
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/DesignPatterns.Strategy.csproj b/DesignPatterns/src/app/DesignPatterns.Strategy/DesignPatterns.Strategy.csproj new file mode 100644 index 0000000..ef60089 --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/DesignPatterns.Strategy.csproj @@ -0,0 +1,57 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{CE978D24-2A8E-46E7-A6B4-406701303485}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>DesignPatterns.Strategy</RootNamespace>
+ <AssemblyName>DesignPatterns.Strategy</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Axe.cs" />
+ <Compile Include="BowAndArrow.cs" />
+ <Compile Include="Character.cs" />
+ <Compile Include="IWeapon.cs" />
+ <Compile Include="King.cs" />
+ <Compile Include="Knife.cs" />
+ <Compile Include="Knight.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Queen.cs" />
+ <Compile Include="Sword.cs" />
+ <Compile Include="test.cs" />
+ <Compile Include="Troll.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/IWeapon.cs b/DesignPatterns/src/app/DesignPatterns.Strategy/IWeapon.cs new file mode 100644 index 0000000..2e4e45b --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/IWeapon.cs @@ -0,0 +1,5 @@ +namespace DesignPatterns.Strategy {
+ public interface IWeapon {
+ void UseWeapon( );
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/King.cs b/DesignPatterns/src/app/DesignPatterns.Strategy/King.cs new file mode 100644 index 0000000..54ce486 --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/King.cs @@ -0,0 +1,16 @@ +/*
+ * Created by:
+ * Created: Monday, July 02, 2007
+ */
+
+namespace DesignPatterns.Strategy {
+ public class King : Character {
+ public King( ) : this( new Sword( ) ) {}
+
+ public King( IWeapon weapon ) : base( weapon ) {}
+
+ public override void Fight( ) {
+ Weapon.UseWeapon( );
+ }
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/Knife.cs b/DesignPatterns/src/app/DesignPatterns.Strategy/Knife.cs new file mode 100644 index 0000000..c51b8ed --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/Knife.cs @@ -0,0 +1,14 @@ +/*
+ * Created by:
+ * Created: Monday, July 02, 2007
+ */
+
+using System;
+
+namespace DesignPatterns.Strategy {
+ public class Knife : IWeapon {
+ public void UseWeapon( ) {
+ Console.Out.WriteLine( "Jab with knife!" );
+ }
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/Knight.cs b/DesignPatterns/src/app/DesignPatterns.Strategy/Knight.cs new file mode 100644 index 0000000..affce39 --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/Knight.cs @@ -0,0 +1,16 @@ +/*
+ * Created by:
+ * Created: Monday, July 02, 2007
+ */
+
+namespace DesignPatterns.Strategy {
+ public class Knight : Character {
+ public Knight( ) : this( new Axe( ) ) {}
+
+ public Knight( IWeapon weapon ) : base( weapon ) {}
+
+ public override void Fight( ) {
+ Weapon.UseWeapon( );
+ }
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/Properties/AssemblyInfo.cs b/DesignPatterns/src/app/DesignPatterns.Strategy/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..bd49bf6 --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("DesignPatterns.Strategy")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DesignPatterns.Strategy")]
+[assembly: AssemblyCopyright("Copyright © 2007")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("ef4bff4c-5b2b-4dbe-9265-65a6ec4460a6")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/Queen.cs b/DesignPatterns/src/app/DesignPatterns.Strategy/Queen.cs new file mode 100644 index 0000000..081a7df --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/Queen.cs @@ -0,0 +1,16 @@ +/*
+ * Created by:
+ * Created: Monday, July 02, 2007
+ */
+
+namespace DesignPatterns.Strategy {
+ public class Queen : Character {
+ public Queen( ) : this( new BowAndArrow( ) ) {}
+
+ public Queen( IWeapon weapon ) : base( weapon ) {}
+
+ public override void Fight( ) {
+ Weapon.UseWeapon( );
+ }
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/Sword.cs b/DesignPatterns/src/app/DesignPatterns.Strategy/Sword.cs new file mode 100644 index 0000000..8b773ed --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/Sword.cs @@ -0,0 +1,14 @@ +/*
+ * Created by:
+ * Created: Monday, July 02, 2007
+ */
+
+using System;
+
+namespace DesignPatterns.Strategy {
+ public class Sword : IWeapon {
+ public void UseWeapon( ) {
+ Console.WriteLine( "Thrust Sword!" );
+ }
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/Troll.cs b/DesignPatterns/src/app/DesignPatterns.Strategy/Troll.cs new file mode 100644 index 0000000..699b9e8 --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/Troll.cs @@ -0,0 +1,16 @@ +/*
+ * Created by:
+ * Created: Monday, July 02, 2007
+ */
+
+namespace DesignPatterns.Strategy {
+ public class Troll : Character {
+ public Troll( ) : this( new Knife( ) ) {}
+
+ public Troll( IWeapon weapon ) : base( weapon ) {}
+
+ public override void Fight( ) {
+ Weapon.UseWeapon( );
+ }
+ }
+}
\ No newline at end of file diff --git a/DesignPatterns/src/app/DesignPatterns.Strategy/test.cs b/DesignPatterns/src/app/DesignPatterns.Strategy/test.cs new file mode 100644 index 0000000..09a4c7c --- /dev/null +++ b/DesignPatterns/src/app/DesignPatterns.Strategy/test.cs @@ -0,0 +1,19 @@ +/*
+ * Created by: Mo
+ * Created: Monday, July 02, 2007
+ */
+
+namespace DesignPatterns.Strategy {
+ public class test {
+ public void init( ) {
+ King king = new King( );
+ king.Fight( );
+
+ king.Weapon = new Axe( );
+ king.Fight( );
+
+ king.Weapon = new BowAndArrow( );
+ king.Fight( );
+ }
+ }
+}
\ No newline at end of file |
