diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..c7de2a4 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,22 @@ +public class Main { + + public static void main(String[] args) { + + // Singleton + SingletonLazy s1 = SingletonLazy.getInstancia(); + SingletonLazy s2 = SingletonLazy.getInstancia(); + System.out.println(s1 == s2); + + // Strategy + Robo robo = new Robo(); + robo.setComportamento(new ComportamentoNormal()); + robo.mover(); + + robo.setComportamento(new ComportamentoAgressivo()); + robo.mover(); + + // Facade + Facade facade = new Facade(); + facade.migrarCliente("Gabriel"); + } +} \ No newline at end of file diff --git a/src/facade/Facade.java b/src/facade/Facade.java new file mode 100644 index 0000000..ad4451b --- /dev/null +++ b/src/facade/Facade.java @@ -0,0 +1,6 @@ +public class Facade { + + public void migrarCliente(String nome) { + System.out.println("Cliente " + nome + " migrado com sucesso!"); + } +} \ No newline at end of file diff --git a/src/singleton/SingletonLazy.java b/src/singleton/SingletonLazy.java new file mode 100644 index 0000000..a5c44b4 --- /dev/null +++ b/src/singleton/SingletonLazy.java @@ -0,0 +1,13 @@ +public class SingletonLazy { + + private static SingletonLazy instancia; + + private SingletonLazy() {} + + public static SingletonLazy getInstancia() { + if (instancia == null) { + instancia = new SingletonLazy(); + } + return instancia; + } +} \ No newline at end of file diff --git a/src/strategy/Strategy.java b/src/strategy/Strategy.java new file mode 100644 index 0000000..2e0c046 --- /dev/null +++ b/src/strategy/Strategy.java @@ -0,0 +1,25 @@ +public interface Comportamento { + void mover(); +} +public class ComportamentoNormal implements Comportamento { + public void mover() { + System.out.println("Movendo normalmente"); + } +} +public class ComportamentoAgressivo implements Comportamento { + public void mover() { + System.out.println("Movendo agressivamente"); + } +} +public class Robo { + + private Comportamento comportamento; + + public void setComportamento(Comportamento comportamento) { + this.comportamento = comportamento; + } + + public void mover() { + comportamento.mover(); + } +} \ No newline at end of file