Skip to content

Commit

Permalink
Adding code for Builder pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosX committed Jul 8, 2013
1 parent 7769e55 commit fb5fe13
Show file tree
Hide file tree
Showing 40 changed files with 125 additions and 0 deletions.
Binary file modified bin/br/padroes/abstractFactory/Fiesta.class
Binary file not shown.
Binary file modified bin/br/padroes/abstractFactory/FiestaSedan.class
Binary file not shown.
Binary file modified bin/br/padroes/abstractFactory/Palio.class
Binary file not shown.
Binary file modified bin/br/padroes/abstractFactory/Siena.class
Binary file not shown.
Binary file modified bin/br/padroes/bridge/JanelaDialogo.class
Binary file not shown.
Binary file modified bin/br/padroes/bridge/JanelaLinux.class
Binary file not shown.
Binary file modified bin/br/padroes/bridge/JanelaWindows.class
Binary file not shown.
Binary file added bin/br/padroes/builder/CarroBuilder.class
Binary file not shown.
Binary file added bin/br/padroes/builder/CarroProduct.class
Binary file not shown.
Binary file added bin/br/padroes/builder/Cliente.class
Binary file not shown.
Binary file added bin/br/padroes/builder/ConcessionariaDirector.class
Binary file not shown.
Binary file added bin/br/padroes/builder/FiatBuilder.class
Binary file not shown.
Binary file added bin/br/padroes/builder/VolksBuilder.class
Binary file not shown.
Binary file modified bin/br/padroes/chain/BancoChain.class
Binary file not shown.
Binary file modified bin/br/padroes/chain/Cliente.class
Binary file not shown.
Binary file modified bin/br/padroes/command/Compra.class
Binary file not shown.
Binary file modified bin/br/padroes/composite/seguro/ArquivoComposite.class
Binary file not shown.
Binary file modified bin/br/padroes/composite/transparente/ArquivoComponent.class
Binary file not shown.
Binary file modified bin/br/padroes/composite/transparente/ArquivoComposite.class
Binary file not shown.
Binary file modified bin/br/padroes/composite/transparente/Main.class
Binary file not shown.
Binary file modified bin/br/padroes/decorator/Cachaca.class
Binary file not shown.
Binary file modified bin/br/padroes/facade/SistemaDeInput.class
Binary file not shown.
Binary file modified bin/br/padroes/facade/SistemaDeVideo.class
Binary file not shown.
Binary file modified bin/br/padroes/interpreter/NumeroRomanoInterpreter.class
Binary file not shown.
Binary file modified bin/br/padroes/iterator/IteradorCanais.class
Binary file not shown.
Binary file modified bin/br/padroes/iteratorExterno/IteradorListaDeCanais.class
Binary file not shown.
Binary file modified bin/br/padroes/iteratorExterno/IteradorMatrizDeCanais.class
Binary file not shown.
Binary file modified bin/br/padroes/iteratorExterno/Main.class
Binary file not shown.
Binary file modified bin/br/padroes/mediator/Cliente.class
Binary file not shown.
Binary file modified bin/br/padroes/mediator/MensagemMediator.class
Binary file not shown.
Binary file modified bin/br/padroes/proxy/BancoUsuarios.class
Binary file not shown.
Binary file modified bin/br/padroes/strategy/Funcionario.class
Binary file not shown.
Binary file modified bin/br/padroes/visitor/ArvoreBinaria.class
Binary file not shown.
Binary file modified bin/br/padroes/visitor/Cliente.class
Binary file not shown.
13 changes: 13 additions & 0 deletions src/br/padroes/builder/CarroBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package br.padroes.builder;

public abstract class CarroBuilder {
protected CarroProduct carro = new CarroProduct();
public abstract void buildPreco();
public abstract void buildDscMotor();
public abstract void buildAnoDeFabricacao();
public abstract void buildModelo();
public abstract void buildMontadora();
public CarroProduct getCarro(){
return carro;
};
}
9 changes: 9 additions & 0 deletions src/br/padroes/builder/CarroProduct.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package br.padroes.builder;

public class CarroProduct {
public double preco;
public String dscMotor;
public int anoDeFabricacao;
public String modelo;
public String montadora;
}
23 changes: 23 additions & 0 deletions src/br/padroes/builder/Cliente.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package br.padroes.builder;

public class Cliente {
public static void main(String[] args) {
ConcessionariaDirector concessionaria = new ConcessionariaDirector(
new FiatBuilder());

concessionaria.construirCarro();
CarroProduct carro = concessionaria.getCarro();
System.out.println("Carro: " + carro.modelo + "/" + carro.montadora
+ "\nAno: " + carro.anoDeFabricacao + "\nMotor: "
+ carro.dscMotor + "\nValor: " + carro.preco);

System.out.println();

concessionaria = new ConcessionariaDirector(new VolksBuilder());
concessionaria.construirCarro();
carro = concessionaria.getCarro();
System.out.println("Carro: " + carro.modelo + "/" + carro.montadora
+ "\nAno: " + carro.anoDeFabricacao + "\nMotor: "
+ carro.dscMotor + "\nValor: " + carro.preco);
}
}
21 changes: 21 additions & 0 deletions src/br/padroes/builder/ConcessionariaDirector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package br.padroes.builder;

public class ConcessionariaDirector {
protected CarroBuilder montadora;

public ConcessionariaDirector(CarroBuilder montadora) {
this.montadora = montadora;
}

public void construirCarro() {
montadora.buildPreco();
montadora.buildAnoDeFabricacao();
montadora.buildDscMotor();
montadora.buildModelo();
montadora.buildMontadora();
}

public CarroProduct getCarro() {
return montadora.getCarro();
}
}
30 changes: 30 additions & 0 deletions src/br/padroes/builder/FiatBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package br.padroes.builder;

public class FiatBuilder extends CarroBuilder {

@Override
public void buildPreco() {
carro.preco = 1000.00;
}

@Override
public void buildDscMotor() {
carro.dscMotor = "1.0 Flex";
}

@Override
public void buildAnoDeFabricacao() {
carro.anoDeFabricacao = 2010;
}

@Override
public void buildModelo() {
carro.modelo = "Palio";
}

@Override
public void buildMontadora() {
carro.montadora = "Fiat";
}

}
29 changes: 29 additions & 0 deletions src/br/padroes/builder/VolksBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package br.padroes.builder;

public class VolksBuilder extends CarroBuilder {
@Override
public void buildPreco() {
carro.preco = 1000.00;
}

@Override
public void buildDscMotor() {
carro.dscMotor = "1.0 Flex";
}

@Override
public void buildAnoDeFabricacao() {
carro.anoDeFabricacao = 2010;
}

@Override
public void buildModelo() {
carro.modelo = "Gol";
}

@Override
public void buildMontadora() {
carro.montadora = "VolskWagem";
}

}

0 comments on commit fb5fe13

Please sign in to comment.