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 --- .../DesignPatterns.Observer.csproj | 51 +++++++++++++++++++++ .../src/app/DesignPatterns.Observer/IObserver.cs | 10 +++++ .../src/app/DesignPatterns.Observer/ISubject.cs | 12 +++++ .../src/app/DesignPatterns.Observer/Mo.cs | 52 ++++++++++++++++++++++ .../app/DesignPatterns.Observer/MosMotherInLaw.cs | 35 +++++++++++++++ .../src/app/DesignPatterns.Observer/MosWife.cs | 35 +++++++++++++++ .../Properties/AssemblyInfo.cs | 35 +++++++++++++++ 7 files changed, 230 insertions(+) create mode 100644 DesignPatterns/src/app/DesignPatterns.Observer/DesignPatterns.Observer.csproj create mode 100644 DesignPatterns/src/app/DesignPatterns.Observer/IObserver.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Observer/ISubject.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Observer/Mo.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Observer/MosMotherInLaw.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Observer/MosWife.cs create mode 100644 DesignPatterns/src/app/DesignPatterns.Observer/Properties/AssemblyInfo.cs (limited to 'DesignPatterns/src/app/DesignPatterns.Observer') 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 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {F27673B4-0A21-43A2-B440-70D2CADDB664} + Library + Properties + DesignPatterns.Observer + DesignPatterns.Observer + + + 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.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")] -- cgit v1.2.3