From 8c137f229c36a777ead5cacb3350cb8692646292 Mon Sep 17 00:00:00 2001 From: "mo.khan" Date: Sat, 5 Jan 2008 07:16:52 +0000 Subject: git-svn-id: http://mokhan.googlecode.com/svn/trunk@9 a0a4a051-f042-0410-9e78-9fae330bdb64 --- .../src/app/DesignPatterns.Strategy/Axe.cs | 14 ++++++ .../src/app/DesignPatterns.Strategy/BowAndArrow.cs | 14 ++++++ .../src/app/DesignPatterns.Strategy/Character.cs | 37 ++++++++++++++ .../DesignPatterns.Strategy.csproj | 57 ++++++++++++++++++++++ .../src/app/DesignPatterns.Strategy/IWeapon.cs | 5 ++ .../src/app/DesignPatterns.Strategy/King.cs | 16 ++++++ .../src/app/DesignPatterns.Strategy/Knife.cs | 14 ++++++ .../src/app/DesignPatterns.Strategy/Knight.cs | 16 ++++++ .../Properties/AssemblyInfo.cs | 35 +++++++++++++ .../src/app/DesignPatterns.Strategy/Queen.cs | 16 ++++++ .../src/app/DesignPatterns.Strategy/Sword.cs | 14 ++++++ .../src/app/DesignPatterns.Strategy/Troll.cs | 16 ++++++ .../src/app/DesignPatterns.Strategy/test.cs | 19 ++++++++ 13 files changed, 273 insertions(+) create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/Axe.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/BowAndArrow.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/Character.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/DesignPatterns.Strategy.csproj create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/IWeapon.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/King.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/Knife.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/Knight.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/Properties/AssemblyInfo.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/Queen.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/Sword.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/Troll.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Strategy/test.cs (limited to 'DesignPatterns/src/app/DesignPatterns.Strategy') 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 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {CE978D24-2A8E-46E7-A6B4-406701303485} + Library + Properties + DesignPatterns.Strategy + DesignPatterns.Strategy + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + \ 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 -- cgit v1.2.3