summaryrefslogtreecommitdiff
path: root/DesignPatterns/src
diff options
context:
space:
mode:
authormo.khan <mo.khan@a0a4a051-f042-0410-9e78-9fae330bdb64>2008-01-05 07:16:52 +0000
committermo.khan <mo.khan@a0a4a051-f042-0410-9e78-9fae330bdb64>2008-01-05 07:16:52 +0000
commit8c137f229c36a777ead5cacb3350cb8692646292 (patch)
tree92876c5da0ffd17767e38f94a44415ac27a3c73e /DesignPatterns/src
parentcbdf42a6427eef7849d1ab7731f9185b410431d3 (diff)
git-svn-id: http://mokhan.googlecode.com/svn/trunk@9 a0a4a051-f042-0410-9e78-9fae330bdb64
Diffstat (limited to 'DesignPatterns/src')
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Adapter/DesignPatterns.Adapter.csproj55
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Adapter/DesktopDropDownList.cs30
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Adapter/DropDownListItem.cs19
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListAdapter.cs9
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListItem.cs6
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Adapter/IView.cs5
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Adapter/Presenter.cs18
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Adapter/Properties/AssemblyInfo.cs35
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Adapter/WebDropDownList.cs24
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Bank.cs19
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/BankAccount.cs27
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcBank.cs9
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcBankAccountFactory.cs13
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcChequingAccount.cs5
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcSavingsAccount.cs5
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Currency.cs38
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/DesignPatterns.Factory.csproj65
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Exceptions/CannotAddMoniesException.cs13
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Exceptions/NegativeMoneyException.cs15
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IBank.cs6
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IBankAccount.cs8
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IBankAccountFactory.cs8
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/ICurrency.cs5
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IMoney.cs13
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Money.cs56
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/Properties/AssemblyInfo.cs35
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBank.cs9
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBankAccountFactory.cs13
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBankChequingAccount.cs5
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBankSavingsAccount.cs5
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Observer/DesignPatterns.Observer.csproj51
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Observer/IObserver.cs10
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Observer/ISubject.cs12
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Observer/Mo.cs52
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Observer/MosMotherInLaw.cs35
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Observer/MosWife.cs35
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Observer/Properties/AssemblyInfo.cs35
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/AmountEnteredState.cs32
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/CardSwipedState.cs32
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/DesignPatterns.State.csproj58
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/IPosTerminal.cs19
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/IPosTransaction.cs13
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/IState.cs13
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/IdleState.cs37
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/PinEnteredState.cs31
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/PosTerminal.cs44
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/PosTransaction.cs30
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/ProcessingTransactionState.cs37
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/Properties/AssemblyInfo.cs35
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/TransactionApprovedState.cs36
-rw-r--r--DesignPatterns/src/app/DesignPatterns.State/TransactionRejectedState.cs35
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/Axe.cs14
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/BowAndArrow.cs14
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/Character.cs37
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/DesignPatterns.Strategy.csproj57
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/IWeapon.cs5
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/King.cs16
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/Knife.cs14
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/Knight.cs16
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/Properties/AssemblyInfo.cs35
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/Queen.cs16
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/Sword.cs14
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/Troll.cs16
-rw-r--r--DesignPatterns/src/app/DesignPatterns.Strategy/test.cs19
-rw-r--r--DesignPatterns/src/test/DesignPatterns.Test/BankAccountTest.cs53
-rw-r--r--DesignPatterns/src/test/DesignPatterns.Test/DesignPatterns.Test.csproj63
-rw-r--r--DesignPatterns/src/test/DesignPatterns.Test/MoneyTest.cs52
-rw-r--r--DesignPatterns/src/test/DesignPatterns.Test/PosTerminalTest.cs17
-rw-r--r--DesignPatterns/src/test/DesignPatterns.Test/Properties/AssemblyInfo.cs35
69 files changed, 1748 insertions, 0 deletions
diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/DesignPatterns.Adapter.csproj b/DesignPatterns/src/app/DesignPatterns.Adapter/DesignPatterns.Adapter.csproj
new file mode 100644
index 0000000..c4634e4
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Adapter/DesignPatterns.Adapter.csproj
@@ -0,0 +1,55 @@
+<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>{A96C019F-1A15-4085-A94C-A0C55632A4EB}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>DesignPatterns.Adapter</RootNamespace>
+ <AssemblyName>DesignPatterns.Adapter</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.Web" />
+ <Reference Include="System.Windows.Forms" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="DesktopDropDownList.cs" />
+ <Compile Include="DropDownListItem.cs" />
+ <Compile Include="IDropDownListAdapter.cs" />
+ <Compile Include="IDropDownListItem.cs" />
+ <Compile Include="IView.cs" />
+ <Compile Include="Presenter.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="WebDropDownList.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.Adapter/DesktopDropDownList.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/DesktopDropDownList.cs
new file mode 100644
index 0000000..cc876c4
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Adapter/DesktopDropDownList.cs
@@ -0,0 +1,30 @@
+using System.Collections.Generic;
+using System.Windows.Forms;
+
+namespace DesignPatterns.Adapter {
+ public class DesktopDropDownList : IDropDownListAdapter {
+ public DesktopDropDownList( ComboBox dropDown ) {
+ _dropDown = dropDown;
+ _pairs = new Dictionary< string, IDropDownListItem >( );
+ }
+
+ public void BindTo( IEnumerable< IDropDownListItem > pairs ) {
+ if ( pairs != null ) {
+ _pairs = new Dictionary< string, IDropDownListItem >( );
+
+ foreach ( IDropDownListItem pair in pairs ) {
+ _dropDown.Items.Add( pair.Text );
+ _pairs.Add( pair.Text, pair );
+ }
+ _dropDown.SelectedIndex = 0;
+ }
+ }
+
+ public IDropDownListItem SelectedItem {
+ get { return !string.IsNullOrEmpty( _dropDown.Text ) ? _pairs[ _dropDown.Text ] : null; }
+ }
+
+ private ComboBox _dropDown;
+ private IDictionary< string, IDropDownListItem > _pairs;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/DropDownListItem.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/DropDownListItem.cs
new file mode 100644
index 0000000..7c30efb
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Adapter/DropDownListItem.cs
@@ -0,0 +1,19 @@
+namespace DesignPatterns.Adapter {
+ internal class DropDownListItem : IDropDownListItem {
+ public DropDownListItem( string text, string value ) {
+ _text = text;
+ _value = value;
+ }
+
+ public string Text {
+ get { return _text; }
+ }
+
+ public string Value {
+ get { return _value; }
+ }
+
+ private readonly string _text;
+ private readonly string _value;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListAdapter.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListAdapter.cs
new file mode 100644
index 0000000..ce2338d
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListAdapter.cs
@@ -0,0 +1,9 @@
+using System.Collections.Generic;
+
+namespace DesignPatterns.Adapter {
+ public interface IDropDownListAdapter {
+ void BindTo( IEnumerable< IDropDownListItem > pairs );
+
+ IDropDownListItem SelectedItem { get; }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListItem.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListItem.cs
new file mode 100644
index 0000000..0e1099a
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Adapter/IDropDownListItem.cs
@@ -0,0 +1,6 @@
+namespace DesignPatterns.Adapter {
+ public interface IDropDownListItem {
+ string Text { get; }
+ string Value { get; }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/IView.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/IView.cs
new file mode 100644
index 0000000..28e25dc
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Adapter/IView.cs
@@ -0,0 +1,5 @@
+namespace DesignPatterns.Adapter {
+ public interface IView {
+ IDropDownListAdapter AreYouHappy { get; }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/Presenter.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/Presenter.cs
new file mode 100644
index 0000000..32fe136
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Adapter/Presenter.cs
@@ -0,0 +1,18 @@
+using System.Collections.Generic;
+
+namespace DesignPatterns.Adapter {
+ public class Presenter {
+ private readonly IView _view;
+
+ public Presenter( IView view ) {
+ _view = view;
+ }
+
+ public void Initialize( ) {
+ IList< IDropDownListItem > items = new List< IDropDownListItem >( );
+ items.Add( new DropDownListItem( "Yes", "1" ) );
+ items.Add( new DropDownListItem( "No", "2" ) );
+ _view.AreYouHappy.BindTo( items );
+ }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Adapter/Properties/AssemblyInfo.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..dcbf00d
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Adapter/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.Adapter")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DesignPatterns.Adapter")]
+[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("4d256698-91ca-4e2a-92a4-57a38f6202a9")]
+
+// 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.Adapter/WebDropDownList.cs b/DesignPatterns/src/app/DesignPatterns.Adapter/WebDropDownList.cs
new file mode 100644
index 0000000..e356a71
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Adapter/WebDropDownList.cs
@@ -0,0 +1,24 @@
+using System.Collections.Generic;
+using System.Web.UI.WebControls;
+
+namespace DesignPatterns.Adapter {
+ public class WebDropDownList : IDropDownListAdapter {
+ public WebDropDownList( DropDownList dropDown ) {
+ _dropDown = dropDown;
+ }
+
+ public void BindTo( IEnumerable< IDropDownListItem > pairs ) {
+ if ( pairs != null ) {
+ foreach ( IDropDownListItem pair in pairs ) {
+ _dropDown.Items.Add( new ListItem( pair.Text, pair.Value ) );
+ }
+ }
+ }
+
+ public IDropDownListItem SelectedItem {
+ get { return new DropDownListItem( _dropDown.SelectedItem.Text, _dropDown.SelectedItem.Value ); }
+ }
+
+ private DropDownList _dropDown;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Bank.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Bank.cs
new file mode 100644
index 0000000..ac51e00
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Bank.cs
@@ -0,0 +1,19 @@
+namespace DesignPatterns.Factory {
+ public abstract class Bank : IBank {
+ private readonly string _name;
+
+ public Bank( string name ) {
+ _name = name;
+ }
+
+ public string Name {
+ get { return _name; }
+ }
+
+ public override string ToString( ) {
+ return _name;
+ }
+
+ public abstract IBankAccountFactory GetAccountFactory( );
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/BankAccount.cs b/DesignPatterns/src/app/DesignPatterns.Factory/BankAccount.cs
new file mode 100644
index 0000000..6bde449
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/BankAccount.cs
@@ -0,0 +1,27 @@
+using System;
+using DesignPatterns.Test;
+
+namespace DesignPatterns.Factory {
+ public class BankAccount : IBankAccount {
+ public BankAccount( ) : this( new Money( 0 ) ) {}
+
+ public BankAccount( IMoney balance ) : this( balance, Guid.NewGuid( ).ToString( ) ) {}
+
+ public BankAccount( IMoney balance, string accountNumber ) {
+ _balance = balance;
+ _accountNumber = accountNumber;
+ }
+
+ public IMoney Balance {
+ get { return _balance; }
+ set { _balance = value; }
+ }
+
+ public string AccountNumber {
+ get { return _accountNumber; }
+ }
+
+ private IMoney _balance;
+ private readonly string _accountNumber;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcBank.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcBank.cs
new file mode 100644
index 0000000..b2a80ce
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcBank.cs
@@ -0,0 +1,9 @@
+namespace DesignPatterns.Factory {
+ public class CibcBank : Bank, IBank {
+ public CibcBank( ) : base( "CIBC" ) {}
+
+ public override IBankAccountFactory GetAccountFactory( ) {
+ return new CibcBankAccountFactory( );
+ }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcBankAccountFactory.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcBankAccountFactory.cs
new file mode 100644
index 0000000..23ac864
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcBankAccountFactory.cs
@@ -0,0 +1,13 @@
+using DesignPatterns.Test;
+
+namespace DesignPatterns.Factory {
+ internal class CibcBankAccountFactory : IBankAccountFactory {
+ public IBankAccount CreateChequingAccount( ) {
+ return new CibcChequingAccount( );
+ }
+
+ public IBankAccount CreateSavingsAccount( ) {
+ return new CibcSavingsAccount( );
+ }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcChequingAccount.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcChequingAccount.cs
new file mode 100644
index 0000000..29e4b92
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcChequingAccount.cs
@@ -0,0 +1,5 @@
+using DesignPatterns.Test;
+
+namespace DesignPatterns.Factory {
+ internal class CibcChequingAccount : BankAccount, IBankAccount {}
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcSavingsAccount.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcSavingsAccount.cs
new file mode 100644
index 0000000..1582a1d
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Cibc/CibcSavingsAccount.cs
@@ -0,0 +1,5 @@
+using DesignPatterns.Test;
+
+namespace DesignPatterns.Factory {
+ internal class CibcSavingsAccount : BankAccount, IBankAccount {}
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Currency.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Currency.cs
new file mode 100644
index 0000000..2c0834e
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Currency.cs
@@ -0,0 +1,38 @@
+namespace DesignPatterns.Factory {
+ public class Currency : ICurrency {
+ #region Constructors
+
+ private Currency( string name ) {
+ _name = name;
+ }
+
+ #endregion
+
+ #region Public Properties
+
+ public string Name {
+ get { return _name; }
+ }
+
+ public static readonly ICurrency Canadian = new Currency( "CAD" );
+ public static readonly ICurrency American = new Currency( "USD" );
+ public static readonly ICurrency GreatBritain = new Currency( "GBP" );
+ public static readonly ICurrency EuropeanUnion = new Currency( "EUR" );
+
+ #endregion
+
+ #region Public Methods
+
+ public override string ToString( ) {
+ return _name;
+ }
+
+ #endregion
+
+ #region Private Fields
+
+ private readonly string _name;
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/DesignPatterns.Factory.csproj b/DesignPatterns/src/app/DesignPatterns.Factory/DesignPatterns.Factory.csproj
new file mode 100644
index 0000000..4c50734
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/DesignPatterns.Factory.csproj
@@ -0,0 +1,65 @@
+<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>{0AAEDFE4-421D-4B3B-8629-5A20EC13F379}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>DesignPatterns.Factory</RootNamespace>
+ <AssemblyName>DesignPatterns.Factory</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="Bank.cs" />
+ <Compile Include="BankAccount.cs" />
+ <Compile Include="Exceptions\CannotAddMoniesException.cs" />
+ <Compile Include="Cibc\CibcBank.cs" />
+ <Compile Include="Cibc\CibcBankAccountFactory.cs" />
+ <Compile Include="Cibc\CibcChequingAccount.cs" />
+ <Compile Include="Cibc\CibcSavingsAccount.cs" />
+ <Compile Include="Currency.cs" />
+ <Compile Include="Interfaces\IBank.cs" />
+ <Compile Include="Interfaces\IBankAccount.cs" />
+ <Compile Include="Interfaces\IBankAccountFactory.cs" />
+ <Compile Include="Interfaces\ICurrency.cs" />
+ <Compile Include="Interfaces\IMoney.cs" />
+ <Compile Include="Money.cs" />
+ <Compile Include="Exceptions\NegativeMoneyException.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="RoyalBank\RoyalBank.cs" />
+ <Compile Include="RoyalBank\RoyalBankAccountFactory.cs" />
+ <Compile Include="RoyalBank\RoyalBankChequingAccount.cs" />
+ <Compile Include="RoyalBank\RoyalBankSavingsAccount.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.Factory/Exceptions/CannotAddMoniesException.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Exceptions/CannotAddMoniesException.cs
new file mode 100644
index 0000000..421883c
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Exceptions/CannotAddMoniesException.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Runtime.Serialization;
+
+namespace DesignPatterns.Factory {
+ [Serializable]
+ public class CannotAddMoniesException : ArgumentException
+ {
+ public CannotAddMoniesException() { }
+ public CannotAddMoniesException(string message) : base(message) { }
+ public CannotAddMoniesException(string message, Exception innerException) : base(message, innerException) { }
+ protected CannotAddMoniesException(SerializationInfo info, StreamingContext context) : base(info, context) { }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Exceptions/NegativeMoneyException.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Exceptions/NegativeMoneyException.cs
new file mode 100644
index 0000000..d7d313d
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Exceptions/NegativeMoneyException.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Runtime.Serialization;
+
+namespace DesignPatterns.Factory {
+ [Serializable]
+ public class NegativeMoneyException : ArgumentException {
+ public NegativeMoneyException( ) : this( "Cannot create a negative money." ) {}
+
+ public NegativeMoneyException( string message ) : base( message ) {}
+
+ public NegativeMoneyException( string message, Exception innerException ) : base( message, innerException ) {}
+
+ protected NegativeMoneyException( SerializationInfo info, StreamingContext context ) : base( info, context ) {}
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IBank.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IBank.cs
new file mode 100644
index 0000000..52f1e67
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IBank.cs
@@ -0,0 +1,6 @@
+namespace DesignPatterns.Factory {
+ public interface IBank {
+ string Name { get; }
+ IBankAccountFactory GetAccountFactory( );
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IBankAccount.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IBankAccount.cs
new file mode 100644
index 0000000..f759e8d
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IBankAccount.cs
@@ -0,0 +1,8 @@
+using DesignPatterns.Factory;
+
+namespace DesignPatterns.Test {
+ public interface IBankAccount {
+ IMoney Balance { get; set; }
+ string AccountNumber{ get;}
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IBankAccountFactory.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IBankAccountFactory.cs
new file mode 100644
index 0000000..5099fd8
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IBankAccountFactory.cs
@@ -0,0 +1,8 @@
+using DesignPatterns.Test;
+
+namespace DesignPatterns.Factory {
+ public interface IBankAccountFactory {
+ IBankAccount CreateChequingAccount( );
+ IBankAccount CreateSavingsAccount( );
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/ICurrency.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/ICurrency.cs
new file mode 100644
index 0000000..8f1afd4
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/ICurrency.cs
@@ -0,0 +1,5 @@
+namespace DesignPatterns.Factory {
+ public interface ICurrency {
+ string Name { get; }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IMoney.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IMoney.cs
new file mode 100644
index 0000000..c5392ae
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Interfaces/IMoney.cs
@@ -0,0 +1,13 @@
+using DesignPatterns.Factory;
+
+namespace DesignPatterns.Factory {
+ public interface IMoney {
+ double Amount { get; }
+
+ ICurrency TypeOfCurrency { get; }
+
+ IMoney Add( IMoney other );
+
+ IMoney Subtract( IMoney money );
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Money.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Money.cs
new file mode 100644
index 0000000..956c9a6
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/Money.cs
@@ -0,0 +1,56 @@
+using System;
+
+namespace DesignPatterns.Factory {
+ public class Money : IMoney {
+ public Money( double amount ) : this( amount, Currency.Canadian ) {}
+
+ public Money( double amount, ICurrency currency ) {
+ if ( amount < 0 ) {
+ throw new NegativeMoneyException( );
+ }
+ _amount = amount;
+ _currency = currency;
+ }
+
+ public double Amount {
+ get { return _amount; }
+ }
+
+ public ICurrency TypeOfCurrency {
+ get { return _currency; }
+ }
+
+ public IMoney Add( IMoney other ) {
+ if ( other != null ) {
+ if ( other.TypeOfCurrency.Equals( TypeOfCurrency ) ) {
+ return new Money( other.Amount + Amount );
+ }
+ throw new CannotAddMoniesException( "Cannot add monies of different currency" );
+ }
+ return this;
+ }
+
+ public IMoney Subtract( IMoney money ) {
+ return ( money != null ) ? new Money( Amount - money.Amount ) : null;
+ }
+
+ public override bool Equals( object obj ) {
+ IMoney other = obj as Money;
+ if ( other != null ) {
+ return other.Amount == Amount;
+ }
+ return false;
+ }
+
+ public override int GetHashCode( ) {
+ return base.GetHashCode( ) + new Random( ( int )DateTime.Now.Ticks ).Next( );
+ }
+
+ public override string ToString( ) {
+ return _amount.ToString( "F" );
+ }
+
+ private readonly double _amount;
+ private readonly ICurrency _currency;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/Properties/AssemblyInfo.cs b/DesignPatterns/src/app/DesignPatterns.Factory/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..7e3253a
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/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.Factory")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DesignPatterns.Factory")]
+[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("b2eb7e33-2bbe-4cc0-a003-5ee1c528e811")]
+
+// 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.Factory/RoyalBank/RoyalBank.cs b/DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBank.cs
new file mode 100644
index 0000000..1e234ab
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBank.cs
@@ -0,0 +1,9 @@
+namespace DesignPatterns.Factory {
+ public class RoyalBank : Bank, IBank {
+ public RoyalBank( ) : base( "Royal Bank" ) {}
+
+ public override IBankAccountFactory GetAccountFactory( ) {
+ return new RoyalBankAccountFactory( );
+ }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBankAccountFactory.cs b/DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBankAccountFactory.cs
new file mode 100644
index 0000000..5a3c2a4
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBankAccountFactory.cs
@@ -0,0 +1,13 @@
+using DesignPatterns.Test;
+
+namespace DesignPatterns.Factory {
+ internal class RoyalBankAccountFactory : IBankAccountFactory {
+ public IBankAccount CreateChequingAccount( ) {
+ return new RoyalBankChequingAccount( );
+ }
+
+ public IBankAccount CreateSavingsAccount( ) {
+ return new RoyalBankSavingsAccount( );
+ }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBankChequingAccount.cs b/DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBankChequingAccount.cs
new file mode 100644
index 0000000..30c5d2a
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBankChequingAccount.cs
@@ -0,0 +1,5 @@
+using DesignPatterns.Test;
+
+namespace DesignPatterns.Factory {
+ internal class RoyalBankChequingAccount : BankAccount, IBankAccount {}
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBankSavingsAccount.cs b/DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBankSavingsAccount.cs
new file mode 100644
index 0000000..06d3534
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Factory/RoyalBank/RoyalBankSavingsAccount.cs
@@ -0,0 +1,5 @@
+using DesignPatterns.Test;
+
+namespace DesignPatterns.Factory {
+ internal class RoyalBankSavingsAccount : BankAccount, IBankAccount {}
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Observer/DesignPatterns.Observer.csproj b/DesignPatterns/src/app/DesignPatterns.Observer/DesignPatterns.Observer.csproj
new file mode 100644
index 0000000..e4f4d78
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Observer/DesignPatterns.Observer.csproj
@@ -0,0 +1,51 @@
+<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>{F27673B4-0A21-43A2-B440-70D2CADDB664}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>DesignPatterns.Observer</RootNamespace>
+ <AssemblyName>DesignPatterns.Observer</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="Mo.cs" />
+ <Compile Include="IObserver.cs" />
+ <Compile Include="ISubject.cs" />
+ <Compile Include="MosMotherInLaw.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="MosWife.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.Observer/IObserver.cs b/DesignPatterns/src/app/DesignPatterns.Observer/IObserver.cs
new file mode 100644
index 0000000..dd47659
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Observer/IObserver.cs
@@ -0,0 +1,10 @@
+/*
+ * Created by:
+ * Created: Friday, July 06, 2007
+ */
+
+namespace DesignPatterns.Observer {
+ public interface IObserver {
+ void Update();
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Observer/ISubject.cs b/DesignPatterns/src/app/DesignPatterns.Observer/ISubject.cs
new file mode 100644
index 0000000..bd07b67
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Observer/ISubject.cs
@@ -0,0 +1,12 @@
+/*
+ * Created by:
+ * Created: Friday, July 06, 2007
+ */
+
+namespace DesignPatterns.Observer {
+ public interface ISubject {
+ void Add( IObserver observer );
+
+ void Remove( IObserver observer );
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Observer/Mo.cs b/DesignPatterns/src/app/DesignPatterns.Observer/Mo.cs
new file mode 100644
index 0000000..1be3a6b
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Observer/Mo.cs
@@ -0,0 +1,52 @@
+/*
+ * Created by: Mo
+ * Created: Friday, July 06, 2007
+ */
+
+using System;
+using System.Collections.Generic;
+
+namespace DesignPatterns.Observer {
+ public class Mo : ISubject {
+ #region Constructors
+
+ public Mo( ) : this( new List< IObserver >( ) ) {}
+
+ public Mo( IList< IObserver > concernedRelatives ) {
+ _concernedRelatives = concernedRelatives;
+ LookAtCuteGirl += delegate { OnLookedAtCuteGirl( ); };
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ public event EventHandler LookAtCuteGirl;
+
+ public void Add( IObserver observer ) {
+ _concernedRelatives.Add( observer );
+ }
+
+ public void Remove( IObserver observer ) {
+ _concernedRelatives.Remove( observer );
+ }
+
+ #endregion
+
+ #region Private Fields
+
+ private IList< IObserver > _concernedRelatives;
+
+ #endregion
+
+ #region Private Methods
+
+ private void OnLookedAtCuteGirl( ) {
+ foreach ( IObserver relative in _concernedRelatives ) {
+ relative.Update( );
+ }
+ }
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Observer/MosMotherInLaw.cs b/DesignPatterns/src/app/DesignPatterns.Observer/MosMotherInLaw.cs
new file mode 100644
index 0000000..a872240
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Observer/MosMotherInLaw.cs
@@ -0,0 +1,35 @@
+/*
+ * Created by: Mo
+ * Created: Friday, July 06, 2007
+ */
+
+using System;
+
+namespace DesignPatterns.Observer {
+ public class MosMotherInLaw : IObserver {
+ #region Constructors
+
+ public MosMotherInLaw( ) : this( new Mo( ) ) {}
+
+ public MosMotherInLaw( ISubject sonInLaw ) {
+ _sonInLaw = sonInLaw;
+ _sonInLaw.Add( this );
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ public void Update( ) {
+ Console.Out.WriteLine( "Why is my son in law looking at cute girls?" );
+ }
+
+ #endregion
+
+ #region Private Fields
+
+ private ISubject _sonInLaw;
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Observer/MosWife.cs b/DesignPatterns/src/app/DesignPatterns.Observer/MosWife.cs
new file mode 100644
index 0000000..756b970
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Observer/MosWife.cs
@@ -0,0 +1,35 @@
+/*
+ * Created by: Mo
+ * Created: Friday, July 06, 2007
+ */
+
+using System;
+
+namespace DesignPatterns.Observer {
+ public class MosWife : IObserver {
+ #region Constructors
+
+ public MosWife( ) : this( new Mo( ) ) {}
+
+ public MosWife( ISubject husband ) {
+ _husband = husband;
+ _husband.Add( this );
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ public void Update( ) {
+ Console.Out.WriteLine( "Why is my husband looking at cute girls?" );
+ }
+
+ #endregion
+
+ #region Private Fields
+
+ private ISubject _husband;
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.Observer/Properties/AssemblyInfo.cs b/DesignPatterns/src/app/DesignPatterns.Observer/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..4a84181
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.Observer/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.Observer")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DesignPatterns.Observer")]
+[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("bbbf5c41-2b3d-40b8-ae7c-da29499173a0")]
+
+// 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.State/AmountEnteredState.cs b/DesignPatterns/src/app/DesignPatterns.State/AmountEnteredState.cs
new file mode 100644
index 0000000..ec27fdc
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/AmountEnteredState.cs
@@ -0,0 +1,32 @@
+using System;
+
+namespace DesignPatterns.State {
+ public class AmountEnteredState : IState {
+ public AmountEnteredState( IPosTerminal terminal ) {
+ _terminal = terminal;
+ }
+
+ public void SwipeCard( string cardNumber ) {
+ Console.Out.WriteLine( "You've already swiped a card!" );
+ }
+
+ public void EnterAmount( double amount ) {
+ Console.Out.WriteLine( "You've already entered an amount" );
+ }
+
+ public void EnterPin( string pin ) {
+ _terminal.Transaction.Pin = pin;
+ _terminal.CurrentState = new PinEnteredState( _terminal );
+ }
+
+ public void ProcessTransaction( ) {
+ Console.Out.WriteLine( "You haven't entered an amount yet." );
+ }
+
+ public void PrintReceipt( ) {
+ Console.Out.WriteLine( "You haven't entered an amount yet." );
+ }
+
+ private IPosTerminal _terminal;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.State/CardSwipedState.cs b/DesignPatterns/src/app/DesignPatterns.State/CardSwipedState.cs
new file mode 100644
index 0000000..ee3a24a
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/CardSwipedState.cs
@@ -0,0 +1,32 @@
+using System;
+
+namespace DesignPatterns.State {
+ public class CardSwipedState : IState {
+ public CardSwipedState( IPosTerminal terminal ) {
+ _terminal = terminal;
+ }
+
+ public void SwipeCard( string cardNumber ) {
+ Console.Out.WriteLine( "You already swiped a card" );
+ }
+
+ public void EnterAmount( double amount ) {
+ _terminal.Transaction.Amount = amount;
+ _terminal.CurrentState = new AmountEnteredState( _terminal );
+ }
+
+ public void EnterPin( string pin ) {
+ Console.Out.WriteLine( "You haven't swiped a card yet!" );
+ }
+
+ public void ProcessTransaction( ) {
+ Console.Out.WriteLine( "You haven't swiped a card yet!" );
+ }
+
+ public void PrintReceipt( ) {
+ Console.Out.WriteLine( "You haven't swiped a card yet!" );
+ }
+
+ private IPosTerminal _terminal;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.State/DesignPatterns.State.csproj b/DesignPatterns/src/app/DesignPatterns.State/DesignPatterns.State.csproj
new file mode 100644
index 0000000..faa7708
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/DesignPatterns.State.csproj
@@ -0,0 +1,58 @@
+<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>{21E02E54-3D4F-457A-B521-D2472ABC55CE}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>DesignPatterns.State</RootNamespace>
+ <AssemblyName>DesignPatterns.State</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="AmountEnteredState.cs" />
+ <Compile Include="CardSwipedState.cs" />
+ <Compile Include="IdleState.cs" />
+ <Compile Include="IPosTerminal.cs" />
+ <Compile Include="IPosTransaction.cs" />
+ <Compile Include="IState.cs" />
+ <Compile Include="PinEnteredState.cs" />
+ <Compile Include="PosTerminal.cs" />
+ <Compile Include="PosTransaction.cs" />
+ <Compile Include="ProcessingTransactionState.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="TransactionApprovedState.cs" />
+ <Compile Include="TransactionRejectedState.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.State/IPosTerminal.cs b/DesignPatterns/src/app/DesignPatterns.State/IPosTerminal.cs
new file mode 100644
index 0000000..0e65d89
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/IPosTerminal.cs
@@ -0,0 +1,19 @@
+namespace DesignPatterns.State {
+ public interface IPosTerminal {
+ void SwipeCard( string cardNumber );
+
+ void EnterAmount( double amount );
+
+ void EnterPin( string pin );
+
+ void AuthorizeTransaction( );
+
+ void PrintReceipt( );
+
+ void ProcessTransaction( );
+
+ IState CurrentState { get; set; }
+
+ IPosTransaction Transaction { get; set; }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.State/IPosTransaction.cs b/DesignPatterns/src/app/DesignPatterns.State/IPosTransaction.cs
new file mode 100644
index 0000000..f2ff5cc
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/IPosTransaction.cs
@@ -0,0 +1,13 @@
+using System;
+
+namespace DesignPatterns.State {
+ public interface IPosTransaction {
+ string Pin { get; set; }
+
+ double Amount { get; set; }
+
+ string CardNumber { get; set; }
+
+ DateTime Date { get; set; }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.State/IState.cs b/DesignPatterns/src/app/DesignPatterns.State/IState.cs
new file mode 100644
index 0000000..9a2baac
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/IState.cs
@@ -0,0 +1,13 @@
+namespace DesignPatterns.State {
+ public interface IState {
+ void ProcessTransaction( );
+
+ void PrintReceipt( );
+
+ void SwipeCard( string cardNumber );
+
+ void EnterAmount( double amount );
+
+ void EnterPin( string pin );
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.State/IdleState.cs b/DesignPatterns/src/app/DesignPatterns.State/IdleState.cs
new file mode 100644
index 0000000..52b2bc6
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/IdleState.cs
@@ -0,0 +1,37 @@
+using System;
+
+namespace DesignPatterns.State {
+ public class IdleState : IState {
+ public IdleState( IPosTerminal terminal ) {
+ _terminal = terminal;
+
+ Console.Out.WriteLine( "Mo's POS TERMINAL" );
+ Console.Out.WriteLine( "Please swipe a card:" );
+ }
+
+ public void SwipeCard( string cardNumber ) {
+ _terminal.Transaction = new PosTransaction( );
+ _terminal.Transaction.Date = DateTime.Now;
+ _terminal.Transaction.CardNumber = cardNumber;
+ _terminal.CurrentState = new CardSwipedState( _terminal );
+ }
+
+ public void EnterAmount( double amount ) {
+ Console.Out.WriteLine( "Please swipe a card first." );
+ }
+
+ public void EnterPin( string pin ) {
+ Console.Out.WriteLine( "Please swipe a card first." );
+ }
+
+ public void ProcessTransaction( ) {
+ Console.Out.WriteLine( "Please swipe a card first." );
+ }
+
+ public void PrintReceipt( ) {
+ Console.Out.WriteLine( "Please swipe a card first." );
+ }
+
+ private IPosTerminal _terminal;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.State/PinEnteredState.cs b/DesignPatterns/src/app/DesignPatterns.State/PinEnteredState.cs
new file mode 100644
index 0000000..809186a
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/PinEnteredState.cs
@@ -0,0 +1,31 @@
+using System;
+
+namespace DesignPatterns.State {
+ public class PinEnteredState : IState {
+ public PinEnteredState( IPosTerminal terminal ) {
+ _terminal = terminal;
+ }
+
+ public void SwipeCard( string cardNumber ) {
+ Console.Out.WriteLine( "You've already swiped a card." );
+ }
+
+ public void EnterAmount( double amount ) {
+ Console.Out.WriteLine( "You've already entered an amount." );
+ }
+
+ public void EnterPin( string pin ) {
+ Console.Out.WriteLine( "You've already entered a pin." );
+ }
+
+ public void ProcessTransaction( ) {
+ _terminal.CurrentState = new ProcessingTransactionState( _terminal );
+ }
+
+ public void PrintReceipt( ) {
+ Console.Out.WriteLine( "The transaction needs to be authorized first" );
+ }
+
+ private IPosTerminal _terminal;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.State/PosTerminal.cs b/DesignPatterns/src/app/DesignPatterns.State/PosTerminal.cs
new file mode 100644
index 0000000..4afe62a
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/PosTerminal.cs
@@ -0,0 +1,44 @@
+namespace DesignPatterns.State {
+ public class PosTerminal : IPosTerminal {
+ public PosTerminal( ) {
+ _currentState = new IdleState( this );
+ }
+
+ public IState CurrentState {
+ get { return _currentState; }
+ set { _currentState = value; }
+ }
+
+ public IPosTransaction Transaction {
+ get { return _transaction; }
+ set { _transaction = value; }
+ }
+
+ public void SwipeCard( string cardNumber ) {
+ _currentState.SwipeCard( cardNumber );
+ }
+
+ public void EnterAmount( double amount ) {
+ _currentState.EnterAmount( amount );
+ }
+
+ public void EnterPin( string pin ) {
+ _currentState.EnterPin( pin );
+ }
+
+ public void AuthorizeTransaction( ) {
+ _currentState.ProcessTransaction( );
+ }
+
+ public void PrintReceipt( ) {
+ _currentState.PrintReceipt( );
+ }
+
+ public void ProcessTransaction( ) {
+ _currentState.ProcessTransaction( );
+ }
+
+ private IState _currentState;
+ private IPosTransaction _transaction;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.State/PosTransaction.cs b/DesignPatterns/src/app/DesignPatterns.State/PosTransaction.cs
new file mode 100644
index 0000000..b9d08d9
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/PosTransaction.cs
@@ -0,0 +1,30 @@
+using System;
+
+namespace DesignPatterns.State {
+ internal class PosTransaction : IPosTransaction {
+ public string Pin {
+ get { return _pin; }
+ set { _pin = value; }
+ }
+
+ public double Amount {
+ get { return _amount; }
+ set { _amount = value; }
+ }
+
+ public string CardNumber {
+ get { return _cardNumber; }
+ set { _cardNumber = value; }
+ }
+
+ public DateTime Date {
+ get { return _date; }
+ set { _date = value; }
+ }
+
+ private string _pin;
+ private double _amount;
+ private string _cardNumber;
+ private DateTime _date;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.State/ProcessingTransactionState.cs b/DesignPatterns/src/app/DesignPatterns.State/ProcessingTransactionState.cs
new file mode 100644
index 0000000..f91cae4
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/ProcessingTransactionState.cs
@@ -0,0 +1,37 @@
+using System;
+
+namespace DesignPatterns.State {
+ internal class ProcessingTransactionState : IState {
+ public ProcessingTransactionState( IPosTerminal terminal ) {
+ _terminal = terminal;
+ }
+
+ public void ProcessTransaction( ) {
+ if ( (++_counter % 5) == 0 ) {
+ _terminal.CurrentState = new TransactionRejectedState( _terminal );
+ }
+ else {
+ _terminal.CurrentState = new TransactionApprovedState( _terminal );
+ }
+ }
+
+ public void PrintReceipt( ) {
+ Console.Out.WriteLine( "The transaction needs to be processed first" );
+ }
+
+ public void SwipeCard( string cardNumber ) {
+ Console.Out.WriteLine( "You have already swiped a card" );
+ }
+
+ public void EnterAmount( double amount ) {
+ Console.Out.WriteLine( "You have already entered an amount" );
+ }
+
+ public void EnterPin( string pin ) {
+ Console.Out.WriteLine( "You have already entered a PIN" );
+ }
+
+ private readonly IPosTerminal _terminal;
+ private static int _counter;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.State/Properties/AssemblyInfo.cs b/DesignPatterns/src/app/DesignPatterns.State/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..584bd52
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/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.State")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DesignPatterns.State")]
+[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("7ddf1e6a-6ca6-4775-8fd6-c63e38833f23")]
+
+// 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.State/TransactionApprovedState.cs b/DesignPatterns/src/app/DesignPatterns.State/TransactionApprovedState.cs
new file mode 100644
index 0000000..cfedf2d
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/TransactionApprovedState.cs
@@ -0,0 +1,36 @@
+using System;
+
+namespace DesignPatterns.State {
+ public class TransactionApprovedState : IState {
+ public TransactionApprovedState( IPosTerminal terminal ) {
+ _terminal = terminal;
+ }
+
+ public void SwipeCard( string cardNumber ) {
+ Console.Out.WriteLine( "The transaction was approved" );
+ }
+
+ public void EnterAmount( double amount ) {
+ Console.Out.WriteLine( "The transaction was approved" );
+ }
+
+ public void EnterPin( string pin ) {
+ Console.Out.WriteLine( "The transaction was approved" );
+ }
+
+ public void ProcessTransaction( ) {
+ Console.Out.WriteLine( "The transaction was approved" );
+ }
+
+ public void PrintReceipt( ) {
+ Console.Out.WriteLine( "** Approved **" );
+ Console.Out.WriteLine( "Date: {0}", _terminal.Transaction.Date );
+ Console.Out.WriteLine( "Card Number: {0}", _terminal.Transaction.CardNumber );
+ Console.Out.WriteLine( "Amount: {0}", _terminal.Transaction.Amount );
+
+ _terminal.CurrentState = new IdleState( _terminal );
+ }
+
+ private IPosTerminal _terminal;
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/app/DesignPatterns.State/TransactionRejectedState.cs b/DesignPatterns/src/app/DesignPatterns.State/TransactionRejectedState.cs
new file mode 100644
index 0000000..5a585a3
--- /dev/null
+++ b/DesignPatterns/src/app/DesignPatterns.State/TransactionRejectedState.cs
@@ -0,0 +1,35 @@
+using System;
+
+namespace DesignPatterns.State {
+ public class TransactionRejectedState : IState {
+ public TransactionRejectedState( IPosTerminal terminal ) {
+ _terminal = terminal;
+ }
+
+ public void SwipeCard( string cardNumber ) {
+ Console.Out.WriteLine( "The transaction was rejected" );
+ }
+
+ public void EnterAmount( double amount ) {
+ Console.Out.WriteLine( "The transaction was rejected" );
+ }
+
+ public void EnterPin( string pin ) {
+ Console.Out.WriteLine( "The transaction was rejected" );
+ }
+
+ public void ProcessTransaction( ) {
+ Console.Out.WriteLine( "The transaction was rejected" );
+ }
+
+ public void PrintReceipt( ) {
+ Console.Out.WriteLine("** Rejected **");
+ Console.Out.WriteLine("Date: {0}", _terminal.Transaction.Date);
+ Console.Out.WriteLine("Card Number: {0}", _terminal.Transaction.CardNumber);
+ Console.Out.WriteLine("Amount: {0}", _terminal.Transaction.Amount);
+ _terminal.CurrentState = new IdleState( _terminal );
+ }
+
+ private IPosTerminal _terminal;
+ }
+} \ No newline at end of file
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
diff --git a/DesignPatterns/src/test/DesignPatterns.Test/BankAccountTest.cs b/DesignPatterns/src/test/DesignPatterns.Test/BankAccountTest.cs
new file mode 100644
index 0000000..0c7357a
--- /dev/null
+++ b/DesignPatterns/src/test/DesignPatterns.Test/BankAccountTest.cs
@@ -0,0 +1,53 @@
+using System;
+using DesignPatterns.Test;
+using MbUnit.Framework;
+
+namespace DesignPatterns.Factory {
+ [TestFixture]
+ public class BankAccountTest {
+ [Test]
+ public void Should_Create_A_Cibc_Chequing_Account( ) {
+ IBank bank = new CibcBank( );
+ IBankAccountFactory factory = bank.GetAccountFactory( );
+ IBankAccount chequingAccount = factory.CreateChequingAccount( );
+ Assert.IsTrue( chequingAccount.Balance.Amount == 0, "Should be zero but was: " + chequingAccount.Balance.Amount );
+ }
+
+ [Test]
+ public void Should_Create_A_Cibc_Savings_Account( ) {
+ IBank bank = new CibcBank( );
+ IBankAccountFactory factory = bank.GetAccountFactory( );
+ IBankAccount savingsAccount = factory.CreateSavingsAccount( );
+ Assert.IsTrue( savingsAccount.Balance.Amount == 0, "Should be zero but was: " + savingsAccount.Balance.Amount );
+ }
+
+ [Test]
+ public void Should_Create_A_Royal_Bank_Chequing_Account( ) {
+ IBank bank = new RoyalBank( );
+ IBankAccountFactory factory = bank.GetAccountFactory( );
+ IBankAccount chequingAccount = factory.CreateChequingAccount( );
+ Assert.IsTrue( chequingAccount.Balance.Amount == 0, "Should be zero but was: " + chequingAccount.Balance.Amount );
+ }
+
+ [Test]
+ public void Should_Create_A_Royal_Bank_Savings_Account( ) {
+ IBank bank = new RoyalBank( );
+ IBankAccountFactory factory = bank.GetAccountFactory( );
+ IBankAccount savingsAccount = factory.CreateSavingsAccount( );
+ Assert.IsTrue( savingsAccount.Balance.Amount == 0, "Should be zero but was: " + savingsAccount.Balance.Amount );
+ }
+
+ [Test]
+ public void _Should_Have_A_Balance( ) {
+ IBankAccount account = new BankAccount( new Money( 5 ) );
+ Assert.IsTrue( account.Balance.Equals( new Money( 5 ) ) );
+ }
+
+ [Test]
+ public void Should_Have_Account_Number( ) {
+ string accountNumber = Guid.NewGuid( ).ToString( );
+ IBankAccount account = new BankAccount( new Money( 500 ), accountNumber );
+ Assert.IsTrue( accountNumber == account.AccountNumber );
+ }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/test/DesignPatterns.Test/DesignPatterns.Test.csproj b/DesignPatterns/src/test/DesignPatterns.Test/DesignPatterns.Test.csproj
new file mode 100644
index 0000000..afd60e7
--- /dev/null
+++ b/DesignPatterns/src/test/DesignPatterns.Test/DesignPatterns.Test.csproj
@@ -0,0 +1,63 @@
+<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>{51D18D95-959C-499E-8363-7FEFF817797F}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>DesignPatterns.Test</RootNamespace>
+ <AssemblyName>DesignPatterns.Test</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="MbUnit.Framework, Version=1.0.2700.29885, Culture=neutral, PublicKeyToken=5e72ecd30bc408d5">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\tools\MbUnit\MbUnit.Framework.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="BankAccountTest.cs" />
+ <Compile Include="MoneyTest.cs" />
+ <Compile Include="PosTerminalTest.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\app\DesignPatterns.Factory\DesignPatterns.Factory.csproj">
+ <Project>{0AAEDFE4-421D-4B3B-8629-5A20EC13F379}</Project>
+ <Name>DesignPatterns.Factory</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\..\app\DesignPatterns.State\DesignPatterns.State.csproj">
+ <Project>{21E02E54-3D4F-457A-B521-D2472ABC55CE}</Project>
+ <Name>DesignPatterns.State</Name>
+ </ProjectReference>
+ </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/test/DesignPatterns.Test/MoneyTest.cs b/DesignPatterns/src/test/DesignPatterns.Test/MoneyTest.cs
new file mode 100644
index 0000000..4f999e5
--- /dev/null
+++ b/DesignPatterns/src/test/DesignPatterns.Test/MoneyTest.cs
@@ -0,0 +1,52 @@
+using DesignPatterns.Factory;
+using MbUnit.Framework;
+
+namespace DesignPatterns.Test {
+ [TestFixture]
+ public class MoneyTest {
+ [Test]
+ public void Should_Be_Equal( ) {
+ Assert.IsTrue( new Money( 5 ).Equals( new Money( 5 ) ) );
+ }
+
+ [Test]
+ public void _Should_Be_Able_To_Add_Two_Monies_Together( ) {
+ IMoney sum = new Money( 5 ).Add( new Money( 5 ) );
+ Assert.IsTrue( sum.Equals( new Money( 10 ) ) );
+ }
+
+ [Test]
+ public void _Should_Be_Able_To_Subtract_Two_Monies( ) {
+ IMoney balance = new Money( 5 ).Subtract( new Money( 3 ) );
+ Assert.IsTrue( balance.Equals( new Money( 2 ) ), "Should have a 2 monies" );
+ }
+
+ [Test]
+ public void _Should_Be_Able_To_Subtract_Many_Monies( ) {
+ IMoney balance = new Money( 5 ).Subtract( new Money( 3 ) ).Subtract( new Money( 1 ) );
+ Assert.IsTrue( balance.Equals( new Money( 1 ) ), "Should have 1 monies" );
+ }
+
+ [Test]
+ public void Should_Have_A_Currency( ) {
+ new Money( 5, Currency.Canadian );
+ }
+
+ [Test]
+ [ExpectedException( typeof( CannotAddMoniesException ) )]
+ public void Should_Only_Add_Monies_Of_The_Same_Currency( ) {
+ new Money( 5, Currency.Canadian ).Add( new Money( 5, Currency.American ) );
+ }
+
+ [Test]
+ [ExpectedException( typeof( NegativeMoneyException ) )]
+ public void Should_Not_Be_Able_To_Construct_Negative_Money( ) {
+ new Money( -5 );
+ }
+
+ [Test]
+ public void Should_Return_5_Monies( ) {
+ Assert.IsTrue( new Money( 5 ).Equals( new Money( 5 ).Add( null ) ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/test/DesignPatterns.Test/PosTerminalTest.cs b/DesignPatterns/src/test/DesignPatterns.Test/PosTerminalTest.cs
new file mode 100644
index 0000000..f69e45c
--- /dev/null
+++ b/DesignPatterns/src/test/DesignPatterns.Test/PosTerminalTest.cs
@@ -0,0 +1,17 @@
+using DesignPatterns.State;
+using MbUnit.Framework;
+
+namespace DesignPatterns.Test {
+ [TestFixture]
+ public class PosTerminalTest {
+ [Test]
+ public void Should_( ) {
+ IPosTerminal terminal = new PosTerminal( );
+ terminal.SwipeCard( "6278080000008205" );
+ terminal.EnterAmount( 99.99 );
+ terminal.EnterPin( "8012" );
+ terminal.ProcessTransaction( );
+ terminal.PrintReceipt( );
+ }
+ }
+} \ No newline at end of file
diff --git a/DesignPatterns/src/test/DesignPatterns.Test/Properties/AssemblyInfo.cs b/DesignPatterns/src/test/DesignPatterns.Test/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..bcb5b5d
--- /dev/null
+++ b/DesignPatterns/src/test/DesignPatterns.Test/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.Test")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DesignPatterns.Test")]
+[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("a9a41066-98c3-4ecf-b37f-3fdfb035b12d")]
+
+// 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")]