Skip to content

Commit

Permalink
Mediator
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCancio committed Jan 15, 2021
1 parent cdfeedf commit 4dba443
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 4 deletions.
14 changes: 14 additions & 0 deletions PatternsComportamentais/Mediator/Colega.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Mediator
{
public abstract class Colega
{
protected Mediador mediador;

public Colega(Mediador mediador)
{
this.mediador = mediador;
}
}
}
21 changes: 21 additions & 0 deletions PatternsComportamentais/Mediator/ColegaConcreto1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace Mediator
{
public class ColegaConcreto1 : Colega
{
public ColegaConcreto1(Mediador mediador) : base(mediador)
{
}

public void Enviar(string mensagem)
{
mediador.Enviar(mensagem, this);
}

public void Notificar(string mensagem)
{
Console.WriteLine($"Mnesagem do Colega 1: {mensagem}");
}
}
}
21 changes: 21 additions & 0 deletions PatternsComportamentais/Mediator/ColegaConcreto2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace Mediator
{
public class ColegaConcreto2 : Colega
{
public ColegaConcreto2(Mediador mediador) : base(mediador)
{
}

public void Enviar(string mensagem)
{
mediador.Enviar(mensagem, this);
}

public void Notificar(string mensagem)
{
Console.WriteLine($"Mnesagem do Colega 2: {mensagem}");
}
}
}
8 changes: 8 additions & 0 deletions PatternsComportamentais/Mediator/Mediador.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;
namespace Mediator
{
public abstract class Mediador
{
public abstract void Enviar(string mensagem, Colega colega);
}
}
24 changes: 24 additions & 0 deletions PatternsComportamentais/Mediator/MediadorConcreto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace Mediator
{
public class MediadorConcreto : Mediador
{
public ColegaConcreto1 Colega1 { private get; set; }

public ColegaConcreto2 Colega2 { private get; set; }


public override void Enviar(string mensagem, Colega colega)
{
if(colega == Colega1)
{
Colega2.Notificar(mensagem);
}
else
{
Colega1.Notificar(mensagem);
}
}
}
}
8 changes: 8 additions & 0 deletions PatternsComportamentais/Mediator/Mediator.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>
22 changes: 22 additions & 0 deletions PatternsComportamentais/Mediator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace Mediator
{
class Program
{
static void Main(string[] args)
{
var m = new MediadorConcreto();

var c1 = new ColegaConcreto1(m);
var c2 = new ColegaConcreto2(m);

m.Colega1 = c1;
m.Colega2 = c2;

c1.Enviar("Como você está?");
c2.Enviar("Bem, obrigado!");

}
}
}
14 changes: 10 additions & 4 deletions PatternsComportamentais/PatternsComportamentais.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ 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}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChainOfResponsibility", "ChainOfResponsibility\ChainOfResponsibility.csproj", "{192EB634-E358-4B2E-8D18-8C975B167E33}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Command", "Command\Command.csproj", "{0F54B039-B529-4FB1-BEE8-87D210A08952}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Command", "Command\Command.csproj", "{0F54B039-B529-4FB1-BEE8-87D210A08952}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interpreter", "Interpreter\Interpreter.csproj", "{3854DE72-2962-43F0-8E6C-3112F6AEE85A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Interpreter", "Interpreter\Interpreter.csproj", "{3854DE72-2962-43F0-8E6C-3112F6AEE85A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Iterator", "Iterator\Iterator.csproj", "{DDA2348A-5257-4E65-9400-2C95DE6F6514}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Iterator", "Iterator\Iterator.csproj", "{DDA2348A-5257-4E65-9400-2C95DE6F6514}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mediator", "Mediator\Mediator.csproj", "{4898D85D-190C-4B86-B905-C66EB661CCF2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -33,6 +35,10 @@ Global
{DDA2348A-5257-4E65-9400-2C95DE6F6514}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDA2348A-5257-4E65-9400-2C95DE6F6514}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDA2348A-5257-4E65-9400-2C95DE6F6514}.Release|Any CPU.Build.0 = Release|Any CPU
{4898D85D-190C-4B86-B905-C66EB661CCF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4898D85D-190C-4B86-B905-C66EB661CCF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4898D85D-190C-4B86-B905-C66EB661CCF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4898D85D-190C-4B86-B905-C66EB661CCF2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 4dba443

Please sign in to comment.