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
4dba443
commit cdeee5d
Showing
6 changed files
with
92 additions
and
0 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,9 @@ | ||
using System; | ||
|
||
namespace Memento | ||
{ | ||
public class Caretaker | ||
{ | ||
public Memento Memento { get; set; } | ||
} | ||
} |
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,16 @@ | ||
using System; | ||
|
||
namespace Memento | ||
{ | ||
public class Memento | ||
{ | ||
public string State { get; private set; } | ||
|
||
public Memento(string state) | ||
{ | ||
this.State = state; | ||
} | ||
|
||
|
||
} | ||
} |
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,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; | ||
} | ||
} | ||
} |
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 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); | ||
} | ||
} | ||
} |
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