forked from LucasCancio/design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdfeedf
commit 4dba443
Showing
8 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters