Skip to content

Commit

Permalink
Chain Of Reponsability
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCancio committed Jan 14, 2021
1 parent 8445050 commit 24b21a9
Show file tree
Hide file tree
Showing 13 changed files with 195 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
19 changes: 19 additions & 0 deletions PatternsComportamentais/ChainOfResponsibility/ConcreteHandler1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace ChainOfResponsibility
{
public class ConcreteHandler1 : Handler
{
public override void HandleRequest(int request)
{
if (request >= 0 && request < 10)
{
Console.WriteLine($"{this.GetType().Name} Handled request {request}"); ;
}
else if (sucessor != null)
{
sucessor.HandleRequest(request);
}
}
}
}
19 changes: 19 additions & 0 deletions PatternsComportamentais/ChainOfResponsibility/ConcreteHandler2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace ChainOfResponsibility
{
public class ConcreteHandler2 : Handler
{
public override void HandleRequest(int request)
{
if (request >= 1 && request < 20)
{
Console.WriteLine($"{this.GetType().Name} Handled request {request}"); ;
}
else if (sucessor != null)
{
sucessor.HandleRequest(request);
}
}
}
}
19 changes: 19 additions & 0 deletions PatternsComportamentais/ChainOfResponsibility/ConcreteHandler3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace ChainOfResponsibility
{
public class ConcreteHandler3 : Handler
{
public override void HandleRequest(int request)
{
if (request >= 20 && request < 30)
{
Console.WriteLine($"{this.GetType().Name} Handled request {request}"); ;
}
else if (sucessor != null)
{
sucessor.HandleRequest(request);
}
}
}
}
13 changes: 13 additions & 0 deletions PatternsComportamentais/ChainOfResponsibility/Handler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ChainOfResponsibility
{
public abstract class Handler
{
public Handler sucessor { protected get; set; }

public abstract void HandleRequest(int request);
}
}
26 changes: 26 additions & 0 deletions PatternsComportamentais/ChainOfResponsibility/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace ChainOfResponsibility
{
class Program
{
static void Main(string[] args)
{
Handler h1 = new ConcreteHandler1();

Handler h2 = new ConcreteHandler2();

Handler h3 = new ConcreteHandler3();

h1.sucessor = h2;
h2.sucessor = h3;

int[] requests = { 2, 5, 24, 22, 1, 30, 12 };

foreach (int request in requests)
{
h1.HandleRequest(request);
}
}
}
}
25 changes: 25 additions & 0 deletions PatternsComportamentais/PatternsComportamentais.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainOfResponsibility", "ChainOfResponsibility\ChainOfResponsibility.csproj", "{192EB634-E358-4B2E-8D18-8C975B167E33}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{192EB634-E358-4B2E-8D18-8C975B167E33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{192EB634-E358-4B2E-8D18-8C975B167E33}.Debug|Any CPU.Build.0 = Debug|Any CPU
{192EB634-E358-4B2E-8D18-8C975B167E33}.Release|Any CPU.ActiveCfg = Release|Any CPU
{192EB634-E358-4B2E-8D18-8C975B167E33}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B4D0CD21-800F-44D6-BC8F-77C51EAAC5A6}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions PatternsEstruturais/PatternsEstruturais.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Facade", "Facade\Facade.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flyweight", "Flyweight\Flyweight.csproj", "{E7A40169-9887-4FB6-BD6B-58B3A063569E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Proxy", "Proxy\Proxy.csproj", "{20F171B7-78DC-4DE8-964F-6729C4E47958}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -45,6 +47,10 @@ Global
{E7A40169-9887-4FB6-BD6B-58B3A063569E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7A40169-9887-4FB6-BD6B-58B3A063569E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7A40169-9887-4FB6-BD6B-58B3A063569E}.Release|Any CPU.Build.0 = Release|Any CPU
{20F171B7-78DC-4DE8-964F-6729C4E47958}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20F171B7-78DC-4DE8-964F-6729C4E47958}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20F171B7-78DC-4DE8-964F-6729C4E47958}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20F171B7-78DC-4DE8-964F-6729C4E47958}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
13 changes: 13 additions & 0 deletions PatternsEstruturais/Proxy/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace Proxy
{
class Program
{
static void Main(string[] args)
{
Proxy proxy = new Proxy();
proxy.Requisicao();
}
}
}
18 changes: 18 additions & 0 deletions PatternsEstruturais/Proxy/Proxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Proxy
{
public class Proxy : Subject
{
private RealSubject realSubject;
public override void Requisicao()
{
if(this.realSubject == null)
{
this.realSubject = new RealSubject();
}

this.realSubject.Requisicao();
}
}
}
8 changes: 8 additions & 0 deletions PatternsEstruturais/Proxy/Proxy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
12 changes: 12 additions & 0 deletions PatternsEstruturais/Proxy/RealSubject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Proxy
{
public class RealSubject : Subject
{
public override void Requisicao()
{
Console.WriteLine("Chamando RealSubject.Request()");
}
}
}
9 changes: 9 additions & 0 deletions PatternsEstruturais/Proxy/Subject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Proxy
{
public abstract class Subject
{
public abstract void Requisicao();
}
}

0 comments on commit 24b21a9

Please sign in to comment.