Skip to content

Commit

Permalink
Commit inicial
Browse files Browse the repository at this point in the history
  • Loading branch information
falvojr committed Aug 27, 2021
0 parents commit 7e3d0cc
Show file tree
Hide file tree
Showing 28 changed files with 263 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .classpath
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>
17 changes: 17 additions & 0 deletions .project
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>
14 changes: 14 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
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 added bin/one/digitalinnovation/gof/Test.class
Binary file not shown.
Binary file added bin/one/digitalinnovation/gof/facade/Facade.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bin/one/digitalinnovation/gof/strategy/Robo.class
Binary file not shown.
Binary file added bin/subsistema1/crm/CrmService.class
Binary file not shown.
Binary file added bin/subsistema2/cep/CepApi.class
Binary file not shown.
57 changes: 57 additions & 0 deletions src/one/digitalinnovation/gof/Test.java
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");
}

}
14 changes: 14 additions & 0 deletions src/one/digitalinnovation/gof/facade/Facade.java
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 src/one/digitalinnovation/gof/singleton/SingletonEager.java
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 src/one/digitalinnovation/gof/singleton/SingletonLazy.java
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 src/one/digitalinnovation/gof/singleton/SingletonLazyHolder.java
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 src/one/digitalinnovation/gof/strategy/Comportamento.java
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 src/one/digitalinnovation/gof/strategy/ComportamentoAgressivo.java
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 src/one/digitalinnovation/gof/strategy/ComportamentoDefensivo.java
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 src/one/digitalinnovation/gof/strategy/ComportamentoNormal.java
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 src/one/digitalinnovation/gof/strategy/Robo.java
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 src/subsistema1/crm/CrmService.java
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 src/subsistema2/cep/CepApi.java
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";
}
}

0 comments on commit 7e3d0cc

Please sign in to comment.