Skip to content

Commit 7e94d49

Browse files
committed
add "chain of responsibility" pattern
0 parents  commit 7e94d49

File tree

10 files changed

+260
-0
lines changed

10 files changed

+260
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.suo
2+
*.manifest
3+
*.user
4+
*.pidb
5+
*.DS_Store
6+
TestResults
7+
Debug/
8+
Release/
9+
obj/
10+
bin/
11+
Bin/
12+
ClientBin/
13+
clientbin/
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{A291BF92-4BE9-42DB-9414-8E09F04FD3F0}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>ChainOfResponsibility</RootNamespace>
12+
<AssemblyName>ChainOfResponsibility</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
15+
<FileAlignment>512</FileAlignment>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
18+
<PlatformTarget>x86</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
28+
<PlatformTarget>x86</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
37+
<DebugSymbols>true</DebugSymbols>
38+
<OutputPath>bin\Debug\</OutputPath>
39+
<DefineConstants>DEBUG;TRACE</DefineConstants>
40+
<DebugType>full</DebugType>
41+
<PlatformTarget>AnyCPU</PlatformTarget>
42+
<CodeAnalysisLogFile>bin\Debug\ChainOfResponsibility.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
43+
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
44+
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
45+
<ErrorReport>prompt</ErrorReport>
46+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
47+
<CodeAnalysisRuleSetDirectories>;D:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
48+
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
49+
<CodeAnalysisRuleDirectories>;D:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
50+
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
51+
</PropertyGroup>
52+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
53+
<OutputPath>bin\Release\</OutputPath>
54+
<DefineConstants>TRACE</DefineConstants>
55+
<Optimize>true</Optimize>
56+
<DebugType>pdbonly</DebugType>
57+
<PlatformTarget>AnyCPU</PlatformTarget>
58+
<CodeAnalysisLogFile>bin\Release\ChainOfResponsibility.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
59+
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
60+
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
61+
<ErrorReport>prompt</ErrorReport>
62+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
63+
<CodeAnalysisRuleSetDirectories>;D:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
64+
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
65+
<CodeAnalysisRuleDirectories>;D:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
66+
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
67+
</PropertyGroup>
68+
<ItemGroup>
69+
<Reference Include="System" />
70+
<Reference Include="System.Core" />
71+
<Reference Include="System.Xml.Linq" />
72+
<Reference Include="System.Data.DataSetExtensions" />
73+
<Reference Include="Microsoft.CSharp" />
74+
<Reference Include="System.Data" />
75+
<Reference Include="System.Xml" />
76+
</ItemGroup>
77+
<ItemGroup>
78+
<Compile Include="ConcreteHandler1.cs" />
79+
<Compile Include="ConcreteHandler2.cs" />
80+
<Compile Include="Handler.cs" />
81+
<Compile Include="Client.cs" />
82+
<Compile Include="Properties\AssemblyInfo.cs" />
83+
<Compile Include="Request.cs" />
84+
</ItemGroup>
85+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
86+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
87+
Other similar extension points exist, see Microsoft.Common.targets.
88+
<Target Name="BeforeBuild">
89+
</Target>
90+
<Target Name="AfterBuild">
91+
</Target>
92+
-->
93+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace ChainOfResponsibility {
7+
8+
class Client {
9+
10+
static void Main(string[] args) {
11+
Handler handlerChain = new ConcreteHandler1(new ConcreteHandler2(null));
12+
13+
Request request1 = new ConcreteRequest1();
14+
handlerChain.HandleRequest(request1);
15+
16+
Request request2 = new ConcreteRequest2();
17+
handlerChain.HandleRequest(request2);
18+
19+
Console.ReadKey();
20+
}
21+
}
22+
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
namespace ChainOfResponsibility {
4+
5+
public class ConcreteHandler1 : Handler {
6+
7+
public ConcreteHandler1(Handler successor) : base(successor) {
8+
}
9+
10+
public override void HandleRequest(Request request) {
11+
if (request is ConcreteRequest1) {
12+
Console.WriteLine("ConcreteRequest1 is handled by ConcreteHandler1");
13+
}
14+
else {
15+
this.Successor.HandleRequest(request);
16+
}
17+
}
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
namespace ChainOfResponsibility {
4+
5+
public class ConcreteHandler2 : Handler {
6+
7+
public ConcreteHandler2(Handler successor) : base(successor) {
8+
}
9+
10+
public override void HandleRequest(Request request) {
11+
if (request is ConcreteRequest2) {
12+
Console.WriteLine("ConcreteRequest2 is handled by ConcreteHandler2");
13+
}
14+
else {
15+
this.Successor.HandleRequest(request);
16+
}
17+
}
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace ChainOfResponsibility {
2+
3+
public abstract class Handler {
4+
5+
private readonly Handler _successor;
6+
7+
protected Handler(Handler successor) {
8+
this._successor = successor;
9+
}
10+
11+
protected Handler Successor {
12+
get {
13+
return this._successor;
14+
}
15+
}
16+
17+
public abstract void HandleRequest(Request request);
18+
19+
}
20+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("ChainOfResponsibility")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ChainOfResponsibility")]
13+
[assembly: AssemblyCopyright("Copyright © 2012")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("9e6bee19-8a0a-4b35-9b34-29556b0be99a")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace ChainOfResponsibility {
2+
3+
public abstract class Request {
4+
}
5+
6+
public class ConcreteRequest1 : Request {
7+
}
8+
9+
public class ConcreteRequest2 : Request {
10+
}
11+
}

DesignPatterns.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Behavioral", "Behavioral", "{B3C3F0E2-50B6-450B-A161-F4500F4E681D}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainOfResponsibility", "Behavioral\ChainOfResponsibility\ChainOfResponsibility.csproj", "{A291BF92-4BE9-42DB-9414-8E09F04FD3F0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{A291BF92-4BE9-42DB-9414-8E09F04FD3F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{A291BF92-4BE9-42DB-9414-8E09F04FD3F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{A291BF92-4BE9-42DB-9414-8E09F04FD3F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{A291BF92-4BE9-42DB-9414-8E09F04FD3F0}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(NestedProjects) = preSolution
23+
{A291BF92-4BE9-42DB-9414-8E09F04FD3F0} = {B3C3F0E2-50B6-450B-A161-F4500F4E681D}
24+
EndGlobalSection
25+
EndGlobal

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CSharp Design Patterns

0 commit comments

Comments
 (0)