Skip to content

Commit c3652eb

Browse files
committed
Melhorias
1 parent 22802a3 commit c3652eb

25 files changed

+249
-18
lines changed

EP.SOLID/1 - SRP/SRP.Violacao/Cliente.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public string AdicionarCliente()
5050
};
5151

5252
mail.Subject = "Bem Vindo.";
53-
mail.Body = "Parabéns! Você está casastrado.";
53+
mail.Body = "Parabéns! Você está cadastrado.";
5454
client.Send(mail);
5555

5656
return "Cliente cadastrado com sucesso!";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
3+
namespace EP.SOLID.OCP.Solucao_Extension_Methods
4+
{
5+
public class CaixaEletronico
6+
{
7+
public static void Operacoes()
8+
{
9+
MenuOperacoes();
10+
11+
var opcao = Console.ReadKey();
12+
var retorno = string.Empty;
13+
14+
var debitoConta = DadosDebito();
15+
16+
switch (opcao.KeyChar)
17+
{
18+
case '1':
19+
Console.WriteLine("Efetuando operação em Conta Corrente");
20+
retorno = debitoConta.DebitarContaCorrente();
21+
break;
22+
case '2':
23+
Console.WriteLine("Efetuando operação em Conta Poupança");
24+
retorno = debitoConta.DebitarContaPoupanca();
25+
break;
26+
case '3':
27+
Console.WriteLine("Efetuando operação em Conta Investimento");
28+
retorno = debitoConta.DebitarContaInvestimento();
29+
break;
30+
}
31+
32+
RetornoTransacao(retorno);
33+
}
34+
35+
private static void MenuOperacoes()
36+
{
37+
Console.Clear();
38+
Console.WriteLine("Caixa Eletrônico SOLID");
39+
Console.WriteLine("Escolha sua opção:");
40+
Console.WriteLine();
41+
Console.WriteLine("1 - Saque Conta Corrente");
42+
Console.WriteLine("2 - Saque Conta Poupança");
43+
Console.WriteLine("3 - Saque Conta Investimento");
44+
}
45+
46+
private static DebitoConta DadosDebito()
47+
{
48+
Console.WriteLine();
49+
Console.WriteLine("..............................");
50+
Console.WriteLine();
51+
Console.WriteLine("Digite a Conta");
52+
var conta = Console.ReadLine();
53+
Console.WriteLine("Digite o Valor");
54+
var valor = Convert.ToDecimal(Console.ReadLine());
55+
56+
var debitoConta = new DebitoConta()
57+
{
58+
NumeroConta = conta,
59+
Valor = valor
60+
};
61+
62+
return debitoConta;
63+
}
64+
65+
private static void RetornoTransacao(string retorno)
66+
{
67+
Console.WriteLine();
68+
Console.WriteLine("Sucesso! Transação: " + retorno);
69+
Console.ReadKey();
70+
}
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Linq;
3+
4+
namespace EP.SOLID.OCP.Solucao_Extension_Methods
5+
{
6+
public class DebitoConta
7+
{
8+
public string NumeroConta { get; set; }
9+
public decimal Valor { get; set; }
10+
public string NumeroTransacao { get; set; }
11+
12+
public string FormatarTransacao()
13+
{
14+
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
15+
var random = new Random();
16+
NumeroTransacao = new string(Enumerable.Repeat(chars, 15)
17+
.Select(s => s[random.Next(s.Length)]).ToArray());
18+
19+
// Numero de transacao formatado
20+
return NumeroTransacao;
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace EP.SOLID.OCP.Solucao_Extension_Methods
2+
{
3+
public static class DebitoContaCorrente
4+
{
5+
public static string DebitarContaCorrente(this DebitoConta debitoConta)
6+
{
7+
// Logica de negócio para debito em conta corrente.
8+
return debitoConta.FormatarTransacao();
9+
}
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace EP.SOLID.OCP.Solucao_Extension_Methods
2+
{
3+
public static class DebitoContaInvestimento
4+
{
5+
public static string DebitarContaInvestimento(this DebitoConta debitoConta)
6+
{
7+
// Logica de negócio para debito em conta investimento.
8+
return debitoConta.FormatarTransacao();
9+
}
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace EP.SOLID.OCP.Solucao_Extension_Methods
2+
{
3+
public static class DebitoContaPoupanca
4+
{
5+
public static string DebitarContaPoupanca(this DebitoConta debitoConta)
6+
{
7+
// Logica de negócio para debito em conta poupanca.
8+
return debitoConta.FormatarTransacao();
9+
}
10+
}
11+
}
+15-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
namespace EP.SOLID.OCP.Solucao
1+
using System;
2+
using System.Linq;
3+
4+
namespace EP.SOLID.OCP.Solucao
25
{
36
public abstract class DebitoConta
47
{
58
public string NumeroTransacao { get; set; }
69
public abstract string Debitar(decimal valor, string conta);
10+
11+
public string FormatarTransacao()
12+
{
13+
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
14+
var random = new Random();
15+
NumeroTransacao = new string(Enumerable.Repeat(chars, 15)
16+
.Select(s => s[random.Next(s.Length)]).ToArray());
17+
18+
// Numero de transacao formatado
19+
return NumeroTransacao;
20+
}
721
}
822
}

EP.SOLID/2 - OCP/OCP.Solucao/DebitoContaCorrente.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class DebitoContaCorrente : DebitoConta
55
public override string Debitar(decimal valor, string conta)
66
{
77
// Debita Conta Corrente
8-
return NumeroTransacao;
8+
return FormatarTransacao();
99
}
1010
}
1111
}

EP.SOLID/2 - OCP/OCP.Solucao/DebitoContaInvestimento.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public override string Debitar(decimal valor, string conta)
66
{
77
// Debita Conta Investimento
88
// Isentar Taxas
9-
return NumeroTransacao;
9+
return FormatarTransacao();
1010
}
1111
}
1212
}

EP.SOLID/2 - OCP/OCP.Solucao/DebitoContaPoupanca.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public override string Debitar(decimal valor, string conta)
66
{
77
// Valida Aniversário da Conta
88
// Debita Conta Corrente
9-
return NumeroTransacao;
9+
return FormatarTransacao();
1010
}
1111
}
1212
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace EP.SOLID.LSP.Solucao
2+
{
3+
public abstract class Paralelogramo
4+
{
5+
protected Paralelogramo(int altura, int largura)
6+
{
7+
Altura = altura;
8+
Largura = largura;
9+
}
10+
11+
public double Altura { get; private set; }
12+
public double Largura { get; private set ; }
13+
public double Area { get { return Altura * Largura; } }
14+
}
15+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace EP.SOLID.LSP.Solucao
4+
{
5+
public class Quadrado : Paralelogramo
6+
{
7+
public Quadrado(int altura, int largura)
8+
: base(altura, largura)
9+
{
10+
if(largura != altura)
11+
throw new ArgumentException("Os dois lados do quadrado precisam ser iguais");
12+
}
13+
}
14+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace EP.SOLID.LSP.Solucao
2+
{
3+
public class Retangulo : Paralelogramo
4+
{
5+
public Retangulo(int altura, int largura)
6+
:base(altura,largura)
7+
{
8+
9+
}
10+
}
11+
}

EP.SOLID/3 - LSP/LSP.Violacao/Program.cs EP.SOLID/3 - LSP/LSP.Violacao/CalculoArea.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
namespace EP.SOLID.LSP.Violacao
44
{
5-
public class Program
5+
public class CalculoArea
66
{
77
private static void ObterAreaRetangulo(Retangulo ret)
88
{
9+
Console.Clear();
910
Console.WriteLine("Calculo da área do Retangulo");
10-
Console.WriteLine(ret.Altura.ToString() + " * " + ret.Largura.ToString());
11+
Console.WriteLine();
12+
Console.WriteLine(ret.Altura + " * " + ret.Largura);
13+
Console.WriteLine();
1114
Console.WriteLine(ret.Area);
1215
Console.ReadKey();
1316
}
1417

15-
private static void Main()
18+
public static void Calcular()
1619
{
1720
var quad = new Quadrado()
1821
{

EP.SOLID/4 - ISP/ISP.Solucao/CadastroCliente.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace EP.SOLID.ISP.Solucao
1+
using EP.SOLID.ISP.Solucao.Interfaces;
2+
3+
namespace EP.SOLID.ISP.Solucao
24
{
35
public class CadastroCliente : ICadastroCliente
46
{

EP.SOLID/4 - ISP/ISP.Solucao/CadastroProduto.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using EP.SOLID.ISP.Solucao.Interfaces;
2+
13
namespace EP.SOLID.ISP.Solucao
24
{
35
public class CadastroProduto : ICadastroProduto

EP.SOLID/4 - ISP/ISP.Solucao/ICadastroCliente.cs EP.SOLID/4 - ISP/ISP.Solucao/Interfaces/ICadastroCliente.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace EP.SOLID.ISP.Solucao
1+
namespace EP.SOLID.ISP.Solucao.Interfaces
22
{
33
public interface ICadastroCliente
44
{

EP.SOLID/4 - ISP/ISP.Solucao/ICadastroProduto.cs EP.SOLID/4 - ISP/ISP.Solucao/Interfaces/ICadastroProduto.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace EP.SOLID.ISP.Solucao
1+
namespace EP.SOLID.ISP.Solucao.Interfaces
22
{
33
public interface ICadastroProduto
44
{

EP.SOLID/4 - ISP/ISP.Violacao/CadastroProduto.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace EP.SOLID.ISP.Violacao
24
{
35
public class CadastroProduto : ICadastro
@@ -15,6 +17,7 @@ public void SalvarBanco()
1517
public void EnviarEmail()
1618
{
1719
// Produto não tem e-mail, o que eu faço agora???
20+
throw new NotImplementedException("Esse metodo não serve pra nada");
1821
}
1922
}
2023
}

EP.SOLID/5 - DIP/DIP.Solucao/ClienteRepository.cs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class ClienteRepository : IClienteRepository
88
{
99
public void AdicionarCliente(Cliente cliente)
1010
{
11+
1112
using (var cn = new SqlConnection())
1213
{
1314
var cmd = new SqlCommand();
@@ -25,6 +26,7 @@ public void AdicionarCliente(Cliente cliente)
2526
cn.Open();
2627
cmd.ExecuteNonQuery();
2728
}
29+
2830
}
2931
}
3032
}

EP.SOLID/5 - DIP/DIP.Solucao/ClienteServices.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ public class ClienteServices : IClienteServices
88
private readonly IEmailServices _emailServices;
99

1010
public ClienteServices(
11-
IClienteRepository clienteRepository,
12-
IEmailServices emailServices)
11+
IEmailServices emailServices,
12+
IClienteRepository clienteRepository)
1313
{
14-
_clienteRepository = clienteRepository;
1514
_emailServices = emailServices;
15+
_clienteRepository = clienteRepository;
1616
}
1717

1818
public string AdicionarCliente(Cliente cliente)

EP.SOLID/5 - DIP/DIP.Violacao/ClienteRepository.cs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace EP.SOLID.DIP.Violacao
55
{
66
public class ClienteRepository
77
{
8+
89
public void AdicionarCliente(Cliente cliente)
910
{
1011
using (var cn = new SqlConnection())

EP.SOLID/EP.SOLID.csproj

+12-3
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,30 @@
4040
<Compile Include="1 - SRP\SRP.Solucao\ClienteRepository.cs" />
4141
<Compile Include="1 - SRP\SRP.Solucao\CPFServices.cs" />
4242
<Compile Include="1 - SRP\SRP.Solucao\EmailServices.cs" />
43+
<Compile Include="2 - OCP\OCP.Solucao Extension Methods\CaixaEletronico.cs" />
44+
<Compile Include="2 - OCP\OCP.Solucao Extension Methods\DebitoConta.cs" />
45+
<Compile Include="2 - OCP\OCP.Solucao Extension Methods\DebitoContaInvestimento.cs" />
46+
<Compile Include="2 - OCP\OCP.Solucao Extension Methods\DebitoContaPoupanca.cs" />
47+
<Compile Include="2 - OCP\OCP.Solucao Extension Methods\DebitoContaCorrente.cs" />
4348
<Compile Include="2 - OCP\OCP.Violacao\DebitoConta.cs" />
4449
<Compile Include="2 - OCP\OCP.Violacao\TipoConta.cs" />
4550
<Compile Include="2 - OCP\OCP.Solucao\DebitoConta.cs" />
4651
<Compile Include="2 - OCP\OCP.Solucao\DebitoContaInvestimento.cs" />
4752
<Compile Include="2 - OCP\OCP.Solucao\DebitoContaPoupanca.cs" />
4853
<Compile Include="2 - OCP\OCP.Solucao\DebitoContaCorrente.cs" />
49-
<Compile Include="3 - LSP\LSP.Violacao\Program.cs" />
54+
<Compile Include="3 - LSP\LSP.Solucao\Paralelogramo.cs" />
55+
<Compile Include="3 - LSP\LSP.Solucao\Quadrado.cs" />
56+
<Compile Include="3 - LSP\LSP.Solucao\Retangulo.cs" />
57+
<Compile Include="3 - LSP\LSP.Violacao\CalculoArea.cs" />
5058
<Compile Include="3 - LSP\LSP.Violacao\Quadrado.cs" />
5159
<Compile Include="3 - LSP\LSP.Violacao\Retangulo.cs" />
5260
<Compile Include="4 - ISP\ISP.Violacao\CadastroCliente.cs" />
5361
<Compile Include="4 - ISP\ISP.Violacao\CadastroProduto.cs" />
5462
<Compile Include="4 - ISP\ISP.Violacao\ICadastro.cs" />
5563
<Compile Include="4 - ISP\ISP.Solucao\CadastroCliente.cs" />
5664
<Compile Include="4 - ISP\ISP.Solucao\CadastroProduto.cs" />
57-
<Compile Include="4 - ISP\ISP.Solucao\ICadastroCliente.cs" />
58-
<Compile Include="4 - ISP\ISP.Solucao\ICadastroProduto.cs" />
65+
<Compile Include="4 - ISP\ISP.Solucao\Interfaces\ICadastroCliente.cs" />
66+
<Compile Include="4 - ISP\ISP.Solucao\Interfaces\ICadastroProduto.cs" />
5967
<Compile Include="5 - DIP\DIP.Violacao\Cliente.cs" />
6068
<Compile Include="5 - DIP\DIP.Violacao\ClienteRepository.cs" />
6169
<Compile Include="5 - DIP\DIP.Violacao\ClienteService.cs" />
@@ -70,6 +78,7 @@
7078
<Compile Include="5 - DIP\DIP.Solucao\Interfaces\IClienteServices.cs" />
7179
<Compile Include="5 - DIP\DIP.Solucao\Interfaces\ICPFServices.cs" />
7280
<Compile Include="5 - DIP\DIP.Solucao\Interfaces\IEmailServices.cs" />
81+
<Compile Include="Program.cs" />
7382
<Compile Include="Properties\AssemblyInfo.cs" />
7483
</ItemGroup>
7584
<ItemGroup />

0 commit comments

Comments
 (0)