summaryrefslogtreecommitdiff
path: root/DesignPatterns/src/app/DesignPatterns.Observer
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/app/DesignPatterns.Observer
parentcbdf42a6427eef7849d1ab7731f9185b410431d3 (diff)
git-svn-id: http://mokhan.googlecode.com/svn/trunk@9 a0a4a051-f042-0410-9e78-9fae330bdb64
Diffstat (limited to 'DesignPatterns/src/app/DesignPatterns.Observer')
-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
7 files changed, 230 insertions, 0 deletions
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")]