-
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.
Fim Desafio de Projeto: Explorando Padrões de Projetos na Prática com…
… Java
- Loading branch information
Showing
39 changed files
with
1,503 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Desafios-de-Projeto/Explorando-Padroes-de-Projetos-na-Pratica-com-Java/README.md
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,20 @@ | ||
# Desafio de Projeto: Explorando Padrões de Projetos na Prática com Java | ||
|
||
Desafio de Projeto do **Bootcamp GFT START #5 JAVA**, promovido pela [Digital Innovation One](https://www.dio.me). | ||
|
||
|
||
## Descrição do Desafio | ||
|
||
Agora é a sua hora de brilhar! Crie uma solução que explore o conceito de Padrões de Projeto na pŕatica. Para isso, você pode reproduzir um dos projetos que criamos durante as aulas ou, caso se sinta preparado, desenvolver uma nova ideia do zero ;-) | ||
|
||
**Desafio:** Explorando Padrões de Projetos na Prática com Java | ||
|
||
|
||
***Tela da API e POST sendo feito*** | ||
 | ||
|
||
|
||
|
||
|
||
|
||
|
Binary file added
BIN
+77.6 KB
...-Projeto/Explorando-Padroes-de-Projetos-na-Pratica-com-Java/assets/tela-api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions
85
...fios-de-Projeto/Explorando-Padroes-de-Projetos-na-Pratica-com-Java/desafio-de-projeto.txt
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,85 @@ | ||
Instrutor: Venilton FalvoJr GitHub: https://github.com/falvojr | ||
|
||
Explorando Padrões de Projetos na Prática com Java | ||
|
||
DESCRIÇÃO | ||
|
||
Agora é a sua hora de brilhar! Crie uma solução que explore o conceito de Padrões de Projeto na prática. Para isso, você pode reproduzir um dos projetos que criamos durante as aulas ou, caso se sinta preparado, desenvolver uma nova ideia do zero. | ||
|
||
|
||
Apresentação Inicial | ||
|
||
Padrões de Projeto | ||
|
||
São soluções consolidadas para problemas recorrentes no desenvolvimento e manutenção de software orientado a objetos. | ||
O livro Design Patterns: Elements of Reusable Object-Oriented Software (1995) é a principal referência sobre o tema, a qual tornou os autores Gamma, Helm, Johnson e Vlissides conhecidos como "Gang of Four" (GoF). | ||
|
||
São comumente classificados nas seguintes categorias: | ||
|
||
Padrões Criacionais: Abstract Factory, Builder, Factory Method, Prototype, Singleton. | ||
|
||
Padrões Comportamentais: Chain of Responsibility, Iterator, Observer, Strategy, Template Method. | ||
|
||
Padrões Estruturais: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy. | ||
|
||
|
||
Praticando com Java Puro: Singleton | ||
|
||
Permitir a criação de uma única instância de uma classe e fornecer um modo para recuperá-la. | ||
|
||
|
||
Praticando com Java Puro: Strategy | ||
|
||
Simplificar a variação de algoritmos para a resolução de um mesmo problema. | ||
|
||
|
||
Praticando com Java Puro: Facade | ||
|
||
Prover uma interface que reduza a complexidade nas integrações com subsistemas. | ||
|
||
|
||
Praticando com Spring: Introdução | ||
|
||
Spring Framework | ||
|
||
|
||
Explorando alguns padrões de projetos com Spring: | ||
|
||
- Singleton: @Bean e @Autowired; | ||
- Strategy: @Service e @Repository; | ||
- Facade: construiremos uma API REST com o mesmo objetivo desse padrão, abstrair a complexidade das seguintes integrações: Spring Data JPA¹ e ViaCEP (Feign). | ||
|
||
¹ Em memória (usando o "h2"). | ||
|
||
|
||
|
||
Praticando com Spring: Conhecendo o Projeto Base | ||
|
||
https://www.jsonschema2pojo.org | ||
|
||
|
||
Praticando com Spring: Padrões de Projeto em uma API REST | ||
|
||
|
||
Desafio de Projeto | ||
|
||
|
||
127.0.0.1:8080/swagger-ui/index.html | ||
127.0.0.1:8080/clientes | ||
|
||
http://127.0.0.1:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config# | ||
|
||
|
||
Entendendo o Desafio | ||
|
||
|
||
Descrição do Desafio | ||
|
||
Agora é a sua hora de brilhar! Crie uma solução que explore o conceito de Padrões de Projeto na pŕatica. Para isso, você pode reproduzir um dos projetos que criamos durante as aulas ou, caso se sinta preparado, desenvolver uma nova ideia do zero ;-) | ||
|
||
Dica: Além dos projetos/repositórios que criamos para este desafio, caso queira explorar novos padrões de projeto digite no Google: "java design patterns github" ou "java design patterns examples". Com isso, você conhecerá novos padrões e implementações de referência que podem ajudá-lo a dominar esse tema! | ||
|
||
|
||
|
||
|
||
|
10 changes: 10 additions & 0 deletions
10
...to/Explorando-Padroes-de-Projetos-na-Pratica-com-Java/lab-padroes-projeto-java/.classpath
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,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
17 changes: 17 additions & 0 deletions
17
...jeto/Explorando-Padroes-de-Projetos-na-Pratica-com-Java/lab-padroes-projeto-java/.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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>lab-padroes-projeto-java</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
15 changes: 15 additions & 0 deletions
15
...rojetos-na-Pratica-com-Java/lab-padroes-projeto-java/.settings/org.eclipse.jdt.core.prefs
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,15 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=11 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning | ||
org.eclipse.jdt.core.compiler.release=enabled | ||
org.eclipse.jdt.core.compiler.source=16 |
3 changes: 3 additions & 0 deletions
3
...a-Pratica-com-Java/lab-padroes-projeto-java/.settings/org.hibernate.eclipse.console.prefs
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,3 @@ | ||
default.configuration= | ||
eclipse.preferences.version=1 | ||
hibernate3.enabled=false |
6 changes: 6 additions & 0 deletions
6
...ando-Padroes-de-Projetos-na-Pratica-com-Java/lab-padroes-projeto-java/README.md
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,6 @@ | ||
# Explorando Padrões de Projetos na Prática com Java | ||
|
||
Repositório com as implementações dos padrões de projeto explorados no Lab "Explorando Padrões de Projetos na Prática com Java". Especificamente, este projeto explorou alguns padrões usando Java puro: | ||
- Singleton | ||
- Strategy | ||
- Facade |
2 changes: 2 additions & 0 deletions
2
...xplorando-Padroes-de-Projetos-na-Pratica-com-Java/lab-padroes-projeto-java/bin/.gitignore
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,2 @@ | ||
/subsistema2/ | ||
/one/ |
Binary file added
BIN
+749 Bytes
...rojetos-na-Pratica-com-Java/lab-padroes-projeto-java/bin/subsistema1/crm/CrmService.class
Binary file not shown.
57 changes: 57 additions & 0 deletions
57
...etos-na-Pratica-com-Java/lab-padroes-projeto-java/src/one/digitalinnovation/gof/Test.java
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,57 @@ | ||
package one.digitalinnovation.gof; | ||
|
||
import one.digitalinnovation.gof.facade.Facade; | ||
import one.digitalinnovation.gof.singleton.SingletonEager; | ||
import one.digitalinnovation.gof.singleton.SingletonLazy; | ||
import one.digitalinnovation.gof.singleton.SingletonLazyHolder; | ||
import one.digitalinnovation.gof.strategy.Comportamento; | ||
import one.digitalinnovation.gof.strategy.ComportamentoAgressivo; | ||
import one.digitalinnovation.gof.strategy.ComportamentoDefensivo; | ||
import one.digitalinnovation.gof.strategy.ComportamentoNormal; | ||
import one.digitalinnovation.gof.strategy.Robo; | ||
|
||
public class Test { | ||
|
||
public static void main(String[] args) { | ||
|
||
// Singleton | ||
|
||
SingletonLazy lazy = SingletonLazy.getInstancia(); | ||
System.out.println(lazy); | ||
lazy = SingletonLazy.getInstancia(); | ||
System.out.println(lazy); | ||
|
||
SingletonEager eager = SingletonEager.getInstancia(); | ||
System.out.println(eager); | ||
eager = SingletonEager.getInstancia(); | ||
System.out.println(eager); | ||
|
||
SingletonLazyHolder lazyHolder = SingletonLazyHolder.getInstancia(); | ||
System.out.println(lazyHolder); | ||
lazyHolder = SingletonLazyHolder.getInstancia(); | ||
System.out.println(lazyHolder); | ||
|
||
// Strategy | ||
|
||
Comportamento defensivo = new ComportamentoDefensivo(); | ||
Comportamento normal = new ComportamentoNormal(); | ||
Comportamento agressivo = new ComportamentoAgressivo(); | ||
|
||
Robo robo = new Robo(); | ||
robo.setComportamento(normal); | ||
robo.mover(); | ||
robo.mover(); | ||
robo.setComportamento(defensivo); | ||
robo.mover(); | ||
robo.setComportamento(agressivo); | ||
robo.mover(); | ||
robo.mover(); | ||
robo.mover(); | ||
|
||
// Facade | ||
|
||
Facade facade = new Facade(); | ||
facade.migrarCliente("Eduardo", "12630000"); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...ratica-com-Java/lab-padroes-projeto-java/src/one/digitalinnovation/gof/facade/Facade.java
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,14 @@ | ||
package one.digitalinnovation.gof.facade; | ||
|
||
import subsistema1.crm.CrmService; | ||
import subsistema2.cep.CepApi; | ||
|
||
public class Facade { | ||
|
||
public void migrarCliente(String nome, String cep) { | ||
String cidade = CepApi.getInstancia().recuperarCidade(cep); | ||
String estado = CepApi.getInstancia().recuperarEstado(cep); | ||
|
||
CrmService.gravarCliente(nome, cep, cidade, estado); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...Java/lab-padroes-projeto-java/src/one/digitalinnovation/gof/singleton/SingletonEager.java
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,19 @@ | ||
package one.digitalinnovation.gof.singleton; | ||
|
||
/** | ||
* Singleton "apressado". | ||
* | ||
* @author falvojr | ||
*/ | ||
public class SingletonEager { | ||
|
||
private static SingletonEager instancia = new SingletonEager(); | ||
|
||
private SingletonEager() { | ||
super(); | ||
} | ||
|
||
public static SingletonEager getInstancia() { | ||
return instancia; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...-Java/lab-padroes-projeto-java/src/one/digitalinnovation/gof/singleton/SingletonLazy.java
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,22 @@ | ||
package one.digitalinnovation.gof.singleton; | ||
|
||
/** | ||
* Singleton "preguicoso". | ||
* | ||
* @author falvojr | ||
*/ | ||
public class SingletonLazy { | ||
|
||
private static SingletonLazy instancia; | ||
|
||
private SingletonLazy() { | ||
super(); | ||
} | ||
|
||
public static SingletonLazy getInstancia() { | ||
if (instancia == null) { | ||
instancia = new SingletonLazy(); | ||
} | ||
return instancia; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...lab-padroes-projeto-java/src/one/digitalinnovation/gof/singleton/SingletonLazyHolder.java
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,23 @@ | ||
package one.digitalinnovation.gof.singleton; | ||
|
||
/** | ||
* Singleton "Lazy Holder". | ||
* | ||
* @see <a href="https://stackoverflow.com/a/24018148">Referencia</a> | ||
* | ||
* @author falvojr | ||
*/ | ||
public class SingletonLazyHolder { | ||
|
||
private static class InstanceHolder { | ||
public static SingletonLazyHolder instancia = new SingletonLazyHolder(); | ||
} | ||
|
||
private SingletonLazyHolder() { | ||
super(); | ||
} | ||
|
||
public static SingletonLazyHolder getInstancia() { | ||
return InstanceHolder.instancia; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...m-Java/lab-padroes-projeto-java/src/one/digitalinnovation/gof/strategy/Comportamento.java
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,5 @@ | ||
package one.digitalinnovation.gof.strategy; | ||
|
||
public interface Comportamento { | ||
void mover(); | ||
} |
10 changes: 10 additions & 0 deletions
10
...b-padroes-projeto-java/src/one/digitalinnovation/gof/strategy/ComportamentoAgressivo.java
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,10 @@ | ||
package one.digitalinnovation.gof.strategy; | ||
|
||
public class ComportamentoAgressivo implements Comportamento { | ||
|
||
@Override | ||
public void mover() { | ||
System.out.println("Movendo-se agressivamente..."); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...b-padroes-projeto-java/src/one/digitalinnovation/gof/strategy/ComportamentoDefensivo.java
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,10 @@ | ||
package one.digitalinnovation.gof.strategy; | ||
|
||
public class ComportamentoDefensivo implements Comportamento { | ||
|
||
@Override | ||
public void mover() { | ||
System.out.println("Movendo-se defensivamente..."); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
.../lab-padroes-projeto-java/src/one/digitalinnovation/gof/strategy/ComportamentoNormal.java
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,10 @@ | ||
package one.digitalinnovation.gof.strategy; | ||
|
||
public class ComportamentoNormal implements Comportamento { | ||
|
||
@Override | ||
public void mover() { | ||
System.out.println("Movendo-se normalmente..."); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...ratica-com-Java/lab-padroes-projeto-java/src/one/digitalinnovation/gof/strategy/Robo.java
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,14 @@ | ||
package one.digitalinnovation.gof.strategy; | ||
|
||
public class Robo { | ||
|
||
private Comportamento comportamento; | ||
|
||
public void setComportamento(Comportamento comportamento) { | ||
this.comportamento = comportamento; | ||
} | ||
|
||
public void mover() { | ||
comportamento.mover(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...Projetos-na-Pratica-com-Java/lab-padroes-projeto-java/src/subsistema1/crm/CrmService.java
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 @@ | ||
package subsistema1.crm; | ||
|
||
public class CrmService { | ||
|
||
private CrmService() { | ||
super(); | ||
} | ||
|
||
public static void gravarCliente(String nome, String cep, String cidade, String estado) { | ||
System.out.println("Cliente salvo no sistema de CRM:"); | ||
System.out.println(nome); | ||
System.out.println(cep); | ||
System.out.println(cidade); | ||
System.out.println(estado); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...-de-Projetos-na-Pratica-com-Java/lab-padroes-projeto-java/src/subsistema2/cep/CepApi.java
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,22 @@ | ||
package subsistema2.cep; | ||
|
||
public class CepApi { | ||
|
||
private static CepApi instancia = new CepApi(); | ||
|
||
private CepApi() { | ||
super(); | ||
} | ||
|
||
public static CepApi getInstancia() { | ||
return instancia; | ||
} | ||
|
||
public String recuperarCidade(String cep) { | ||
return "Cachoeira Paulista"; | ||
} | ||
|
||
public String recuperarEstado(String cep) { | ||
return "SP"; | ||
} | ||
} |
Oops, something went wrong.