Created
December 6, 2011 16:19
-
-
Save Arthurmourao/1438782 to your computer and use it in GitHub Desktop.
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
package montadora; | |
public abstract class Carros { | |
private String description = "Veiculo"; | |
private String modelN = "Nacional"; | |
private String modelI = "Importado"; | |
public void setmodelN(String mNacional) { | |
modelN = mNacional; | |
} | |
public String getmodelN(){ | |
return modelN; | |
} | |
public void setmodelI(String mImportado) { | |
modelN = mImportado; | |
} | |
public String getmodelI(){ | |
return modelI; | |
} | |
public void setDescription(String desc) { | |
description = desc; | |
} | |
public String getDescription(){ | |
return description; | |
} | |
public abstract double cost(); | |
} |
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
package montadora; | |
public abstract class CarroDecorator extends Carros { | |
/*As classes decorator devem ser espelhos das classes que elas vão decorar. | |
*O motivo de se usar herança na classe Decorator é pelo simples fato | |
*de se ter o mesmo tipo dos objetos que vão ser decorados. | |
*/ | |
} |
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
package montadora; | |
public class ArCondicionado extends CarroDecorator { | |
/*Este é um exemplo de classe decoradora | |
* Aqui "decoramos" nosso carro com um item de ar-condicionado | |
*/ | |
Carros carro; | |
public ArCondicionado(Carros car) { | |
carro = car; | |
} | |
//na descrição do pedido do veículo, incluiremos o nome do item | |
@Override | |
public String getDescription() { | |
return carro.getDescription() + ", Ar-Condicionado"; | |
} | |
//aqui, incluimos o preço do item | |
@Override | |
public double cost() { | |
return 2500.50 + carro.cost(); | |
} | |
} |
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
package montadora; | |
public class MotorFraco extends Carros { | |
/*Esta classe herda diretamente de Carros por ser | |
* um modelo de carro, ele pode ter um motor potente ou fraco como 1.0, 1.6, 2.0, etc, | |
* isto diferencia o modelo. | |
*/ | |
public MotorFraco(){ | |
setDescription("Motor fraco, chassi ruim"); | |
} | |
@Override | |
public double cost() { | |
return 1900.50; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment