forked from digitalinnovationone/lab-padroes-projeto-java
-
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
0 parents
commit 7e3d0cc
Showing
28 changed files
with
263 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,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-16"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</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,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> |
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 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=16 | ||
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 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+675 Bytes
bin/one/digitalinnovation/gof/singleton/SingletonLazyHolder$InstanceHolder.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+659 Bytes
bin/one/digitalinnovation/gof/strategy/ComportamentoAgressivo.class
Binary file not shown.
Binary file added
BIN
+659 Bytes
bin/one/digitalinnovation/gof/strategy/ComportamentoDefensivo.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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("Venilton", "14801788"); | ||
} | ||
|
||
} |
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
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
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 "preguiçoso". | ||
* | ||
* @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
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; | ||
} | ||
} |
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
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
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
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..."); | ||
} | ||
|
||
} |
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(); | ||
} | ||
} |
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); | ||
} | ||
} |
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 "Araraquara"; | ||
} | ||
|
||
public String recuperarEstado(String cep) { | ||
return "SP"; | ||
} | ||
} |