Skip to content

Commit

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

namespace Memento
{
public class Caretaker
{
public Memento Memento { get; set; }
}
}
16 changes: 16 additions & 0 deletions PatternsComportamentais/Memento/Memento.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace Memento
{
public class Memento
{
public string State { get; private set; }

public Memento(string state)
{
this.State = state;
}


}
}
8 changes: 8 additions & 0 deletions PatternsComportamentais/Memento/Memento.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>
29 changes: 29 additions & 0 deletions PatternsComportamentais/Memento/Originator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace Memento
{
public class Originator
{
private string _state;
public string State
{
get { return _state; }
set
{
_state = value;
Console.WriteLine($"State = {value}");
}
}

public Memento CreateMemento()
{
return new Memento(_state);
}

public void SetMemento(Memento memento)
{
Console.WriteLine("Restaurando o estado...");
State = memento.State;
}
}
}
24 changes: 24 additions & 0 deletions PatternsComportamentais/Memento/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace Memento
{
class Program
{
static void Main(string[] args)
{
Originator o = new Originator
{
State = "On"
};

Caretaker c = new Caretaker
{
Memento = o.CreateMemento()
};

o.State = "Off";

o.SetMemento(c.Memento);
}
}
}
6 changes: 6 additions & 0 deletions PatternsComportamentais/PatternsComportamentais.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Iterator", "Iterator\Iterat
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,6 +41,10 @@ Global
{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
{189CDE42-E8FF-4D76-851B-321F75172835}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{189CDE42-E8FF-4D76-851B-321F75172835}.Debug|Any CPU.Build.0 = Debug|Any CPU
{189CDE42-E8FF-4D76-851B-321F75172835}.Release|Any CPU.ActiveCfg = Release|Any CPU
{189CDE42-E8FF-4D76-851B-321F75172835}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit cdeee5d

Please sign in to comment.