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
/* | |
Author: Walter Alleyz | |
Date: 2022-03-29 | |
Objective: Show the main patterns widely used in the object oriented programming scenario. | |
Patterns: Strategy, Chain Of Resposability, Template Method, Observer, Adapter, Decorator, Composite, Proxy and Facade. | |
*/ | |
import java.util.Optional; | |
class Main { |
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
class RevistaInformatica extends Observable { | |
private int edicao; | |
public void setNovaEdicao(int novaEdicao) { | |
this.edicao = novaEdicao; | |
setChanged(); | |
notifyObservers(); | |
} |
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
class No { | |
protected int chave; | |
No esquerdo, direito; | |
public No(int chave) { | |
this.chave = chave; | |
esquerdo = null; | |
direito = null; | |
} | |
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
class Numero implements Operador { | |
private int numero; | |
public Numero(int numero) { | |
this.numero = numero; | |
} | |
@Override | |
public int interpretar() { |
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
interface Desconto { | |
BigDecimal calcular(Pedido pedido); | |
void setProximo(Desconto proximo); | |
} | |
class DescontoPorItens implements Desconto { | |
private Desconto proximo; |
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
abstract class Command { | |
public Editor editor; | |
private String backup; | |
Command(Editor editor) { | |
this.editor = editor; | |
} | |
void backup() { | |
backup = editor.textField.getText(); |
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
class Editor extends JComponent { | |
private Canvas canvas; | |
private CompoundShape allShapes = new CompoundShape(); | |
private History history; | |
public Editor() { | |
canvas = new Canvas(this); | |
history = new History(); | |
} |
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
interface ProfileIterator { | |
boolean hasNext(); | |
Profile getNext(); | |
void reset(); | |
} | |
class FacebookIterator implements ProfileIterator { | |
private Facebook facebook; |
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
interface Component { | |
void setMediator(Mediator mediator); | |
String getName(); | |
} | |
class AddButton extends JButton implements Component { | |
private Mediator mediator; | |
public AddButton() { | |
super("Add"); |
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
abstract class State { | |
Player player; | |
/** | |
* Context passes itself through the state constructor. This may help a | |
* state to fetch some useful context data if needed. | |
*/ | |
State(Player player) { | |
this.player = player; | |
} |
NewerOlder