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
2ed17b1
commit 8c586a4
Showing
5 changed files
with
118 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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30804.86 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Singleton", "Singleton\Singleton.csproj", "{0966E9CC-D967-44E6-B950-20DE58379278}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{0966E9CC-D967-44E6-B950-20DE58379278}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0966E9CC-D967-44E6-B950-20DE58379278}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{0966E9CC-D967-44E6-B950-20DE58379278}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{0966E9CC-D967-44E6-B950-20DE58379278}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {BDC89CB3-F133-4341-A21C-A9B5EDB05D3F} | ||
EndGlobalSection | ||
EndGlobal |
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 Singleton | ||
{ | ||
public sealed class BolaComSingleton | ||
{ | ||
private static BolaComSingleton instancia = null; | ||
|
||
public static BolaComSingleton GetInstancia | ||
{ | ||
get | ||
{ | ||
if (instancia == null) | ||
{ | ||
instancia = new BolaComSingleton(); | ||
Console.WriteLine("Bola em Jogo!"); | ||
} | ||
|
||
return instancia; | ||
|
||
} | ||
} | ||
|
||
public void Mensagem(string msg) | ||
{ | ||
Console.WriteLine(msg); | ||
} | ||
} | ||
} |
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,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Singleton | ||
{ | ||
public class BolaSemSingleton | ||
{ | ||
public BolaSemSingleton() | ||
{ | ||
Console.WriteLine("Bola em Jogo!"); | ||
} | ||
public void Mensagem(string msg) | ||
{ | ||
Console.WriteLine(msg); | ||
} | ||
} | ||
} |
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,38 @@ | ||
using System; | ||
|
||
namespace Singleton | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
UsandoSingleton(); | ||
Console.WriteLine("\n"); | ||
UsandoMetodoTradicional(); | ||
} | ||
|
||
public static void UsandoSingleton() | ||
{ | ||
BolaComSingleton jogador_1 = BolaComSingleton.GetInstancia; | ||
jogador_1.Mensagem("Jogador 1: A bola está comigo no meio de campo"); | ||
|
||
BolaComSingleton jogador_2 = BolaComSingleton.GetInstancia; | ||
jogador_2.Mensagem("Jogador2: recebeu a bola"); | ||
|
||
BolaComSingleton jogador_3 = BolaComSingleton.GetInstancia; | ||
jogador_3.Mensagem("Jogador 3: recebeu o lançamento na linha de fundo"); | ||
} | ||
|
||
public static void UsandoMetodoTradicional() | ||
{ | ||
BolaSemSingleton jogador_1 = new BolaSemSingleton(); | ||
jogador_1.Mensagem("Jogador 1: A bola está comigo no meio de campo"); | ||
|
||
BolaSemSingleton jogador_2 = new BolaSemSingleton(); | ||
jogador_2.Mensagem("Jogador2: recebeu a bola"); | ||
|
||
BolaSemSingleton jogador_3 = new BolaSemSingleton(); | ||
jogador_3.Mensagem("Jogador 3: recebeu o lançamento na linha de fundo"); | ||
} | ||
} | ||
} |
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> |