Skip to content

Commit

Permalink
State
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCancio committed Jan 15, 2021
1 parent 38ee850 commit 26829ef
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 3 deletions.
12 changes: 9 additions & 3 deletions PatternsComportamentais/PatternsComportamentais.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Interpreter", "Interpreter\
EndProject
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}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mediator", "Mediator\Mediator.csproj", "{4898D85D-190C-4B86-B905-C66EB661CCF2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Memento", "Memento\Memento.csproj", "{189CDE42-E8FF-4D76-851B-321F75172835}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Memento", "Memento\Memento.csproj", "{189CDE42-E8FF-4D76-851B-321F75172835}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Observer", "Observer\Observer.csproj", "{88C5750D-1C94-49EA-9402-81EC6DB545AC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Observer", "Observer\Observer.csproj", "{88C5750D-1C94-49EA-9402-81EC6DB545AC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "State", "State\State.csproj", "{D8399170-7DED-4CDC-8FB9-03F3C91CD142}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -51,6 +53,10 @@ Global
{88C5750D-1C94-49EA-9402-81EC6DB545AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88C5750D-1C94-49EA-9402-81EC6DB545AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88C5750D-1C94-49EA-9402-81EC6DB545AC}.Release|Any CPU.Build.0 = Release|Any CPU
{D8399170-7DED-4CDC-8FB9-03F3C91CD142}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8399170-7DED-4CDC-8FB9-03F3C91CD142}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8399170-7DED-4CDC-8FB9-03F3C91CD142}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8399170-7DED-4CDC-8FB9-03F3C91CD142}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 12 additions & 0 deletions PatternsComportamentais/State/ConcreteStateA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace State
{
public class ConcreteStateA : State
{
public override void Handle(Context context)
{
context.State = new ConcreteStateB();
}
}
}
10 changes: 10 additions & 0 deletions PatternsComportamentais/State/ConcreteStateB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace State
{
public class ConcreteStateB : State
{
public override void Handle(Context context)
{
context.State = new ConcreteStateA();
}
}
}
28 changes: 28 additions & 0 deletions PatternsComportamentais/State/Context.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;

namespace State
{
public class Context
{
private State _state;
public State State
{
get { return _state; }
set
{
_state = value;
Console.WriteLine($"Estado: {_state.GetType().Name}");
}
}

public Context(State state)
{
_state = state;
}

public void Request()
{
_state.Handle(this);
}
}
}
17 changes: 17 additions & 0 deletions PatternsComportamentais/State/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace State
{
class Program
{
static void Main(string[] args)
{
Context c = new Context(new ConcreteStateA());

c.Request();
c.Request();
c.Request();
c.Request();
}
}
}
9 changes: 9 additions & 0 deletions PatternsComportamentais/State/State.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace State
{
public abstract class State
{
public abstract void Handle(Context context);
}
}
8 changes: 8 additions & 0 deletions PatternsComportamentais/State/State.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>

0 comments on commit 26829ef

Please sign in to comment.