
- Client: The client is responsible for creating the Command object and setting it's reciever.
public class ClientApp {
public static void main(String[] args) {
Receiver rec = new Receiver();
Command incCommand = new IncrementCommand(rec);
Command decCommand = new DecrementCommand(rec);
Invoker invoker = new Invoker();
invoker.setDecCommand(decCommand);
invoker.setIncCommand(incCommand);
invoker.addRequest();
invoker.addRequest();
invoker.removeRequest();
System.out.println(rec.getValue());
}
}ClientApp.java - Invoker: The Invoker acts as a placeholder for the Command object and invokes the execute method on the Command. In case of undoable commands, it stores the command in a stack (for multi-level undo, or just the command for single level undo), before executing the command.
public class Invoker {
Stack<Command> commands;
Command incCommand;
Command decCommand;
public Invoker() {
commands = new Stack<Command>();
}
public void setIncCommand(Command command) {
incCommand = command;
}
public void setDecCommand(Command command) {
decCommand = command;
}
public void undoAll() {
Command cmd = null;
while (!commands.empty()) {
cmd = commands.pop();
cmd.undo();
}
}
public void addRequest() {
incCommand.execute();
commands.add(incCommand);
}
public void removeRequest() {
decCommand.execute();
commands.add(decCommand);
}
public void commit() {
commands = new Stack<Command>();
}
}Invoker.java - Receiver: The object that performs the operations associated with carrying out a request. Any class may serve as a Receiver.
public class Receiver {
private int value;
public Receiver() {
value = 0;
}
public void increment() {
++value;
}
public void decrement() {
--value;
}
public int getValue() {
return value;
}
}Receiver.java - Command: The command object represents the request operation. The command implements execute() method, which invokes the corresponding operations on the Reciever. This defines a binding between a Receiver object and an action.
public interface Command {
public void execute();
public void undo();
}Command.java public class IncrementCommand implements Command {
Receiver receiver;
public IncrementCommand(Receiver rec) {
receiver = rec;
}
public void execute() {
receiver.increment();
}
public void undo() {
receiver.decrement();
}
}IncrementCommand.java public class DecrementCommand implements Command {
Receiver receiver;
public DecrementCommand(Receiver receiver) {
this.receiver = receiver;
}
public void execute() {
receiver.decrement();
}
public void undo() {
receiver.increment();
}
}DecrementCommand.java
Additional Notes
- A command can have a wide range of abilities from a simple interface between the client and receiver to being a receiver itself.
- When supporting multi-level undo, a command may store state information, which mean that, with each execute(), you have to copy the state of the command at that time. In such cases a copy of the command has to be added to the history stack.
good one!
ReplyDeletehybrid app development in usa
ReplyDeletephp web development in usa
python web development in usa
angular js development in usa
wordpress development company in usa
It will be more fun, and you won't have to worry about
ReplyDeletethepetsabout.com
happylifestyletrends.com
restaurantsnearme-opennow
Lets have a look at a recent news item that is quite
ReplyDeleteentertainmentbee.com
themoviesbio.com
petrefine.com
Everything is going to be alright. Are we really being honest
ReplyDeletefrasesparaenamorarz.com
fras-es.com
punaisesdelit.org
groupe-sanguine.fr
meilleur-gps.fr
abrigo aviador mujer abdomen
ReplyDeletegucci forocoches
sonic 3 and knuckles juego online
short de bain islamique
stihl klamotten
brabus rocket 900 amazon
new balance icarus
sonnenbrille herren mit seitenschutz
hoodie pepe jeans cyan
shorts fitness feminino
melhores marcas de mochilas masculinas
quadri da disegnare amazon
aharry potter x vans
culle e passeggini per neonati amazon
camisa da ferroviária
galocha rosa feminina
deichmann bolsos
bolso de mano de hombre guess entusiasta
tenda da sole spiaggia amazon
nike pegasus 94
Nike Air Force 270
borraccia decathlon amazon
sostituzione cinghia distribuzione seat mii
veste per battesimo amazon
calzoncillos puma hombre
ReplyDeleteadidas originals panna scarpe uomo basse
grossista condizionatori
costumi interi amazon
vestito da elsa disney
adidas yeezy semi frozen yellow on feet
second hand golf 5 gti for sale
piumini daunenstep amazon
pittura x pareti amazon trascorrere
fiore garofano amazon
air force 1 nike outfit men basket
nike air zip up hoodie
king kong jeans
zapatillas running galaxy 4 azul marino mujer adidas
blazer basicos mujer
nike air max de bebe principal opción
zapatos de charol mujer con taco
nike metcon flyknit 3 para running
bolsas para comprimir equipaje
chanclas new balance niña
nike pegasus grey and green
amazon sandalias reef
polo simulator
casquette ford Immigration
ReplyDeletechaussure carla moreau
triciclo usato milano
chaussures de sécurité facom
foot locker nike react element
scatola protezione stagna
nike metcon 5 rojas
zapatillas de agua niña
veste velour carhartt
damen lack schnürer
cappotto rosso scarpe nike
fiore garofano amazon
nike presto extreme pas cher
nike pegasus 94
shorts fitness feminino
nike t shirt tumblr
quadri da disegnare amazon
chinelo slide da melissa
tenis all star feminino branco couro
calzoncillos puma hombre
veste per battesimo amazon
nike air force modelo agotado
cartera levis hombre
filtre pour aspirateur samsung sc4780
autoradio gps vdo
nike tribute veste
soldes chaussures homme caterpillar hiver cafétéria
amazon sandalias reef
chanclas new balance niña
kit de creation de bracelets utilisation
wc suspendu mural amazon
foulard en soie homme
all star converse star player
paragliding přilby
nike anzug nba rot
camisa da ferroviária
tapie adidas credit lyonnais
gucci handbags uk
air force 1 nike outfit men basket
pittura x pareti amazon trascorrere
ReplyDeletepull training nike
nike sb air max bruin vapor
jogging fille 14 ans adidas
outlet nike floresta
nike dual fusion tr iii
maglietta ciglia stradivarius
nike jogginghose dunkelgrau damen
nike academy16 knt tracksuit 2
borraccia decathlon amazon
camisa ponte preta aranha
sandalias de esparto mujer
kiabi bottine femme
polo lacoste ton sur ton
pepe jeans tami
crampon vissé adidas
brassiere garcon
vestido de niña rosa palo
maglia termica nuoto bambina
adidas zx flux adv virtue sock w
nike cortez prm
beutel zipper amazon
nike tanjun damen weiß 44
scarpe pirelli uomo impedire
polo ralph lauren jeanshemd damen
risparmiare batteria iphone ios 12
style année 80 femme
Nike Air Force 270
kimono en jean
pantaloni puma femei pollice Linea di metallo
shein camicie donna cameriera
bañador neopreno mujer oysho
sudadera nike vintage
giacca da prestigiatore
sandalias courofeito a mao
grossista condizionatori
piumini daunenstep amazon
zapatillas cruyff mujer
nike sb prod x
ReplyDeletegucci leather wristband
botas australianas mustang
magnum pi jeans
nike pegasus 94
scatola protezione stagna
shein camicie donna cameriera
nike les halles
nike blazer low 3d
vestido de niña rosa palo
giacca da prestigiatore
sapatenis masculino elastico
sujetador media copa abierto
polo shirt juventus
ladies summer shorts
gucci slides cheap
sandalias agua cerradas
survetement adidas homme militaire
nike t shirt tumblr
nike tanjun damen weiß 44
tumbona terraza ikea
ReplyDeletenike zoom strike sprinter
gants si assault factory pilot noir oakley
camisa cuadros franela mujer
galocha rosa feminina
adidas run falcon on feet
ghete galbene piele
hama stiftplatte einhorn amazon
moleton nike preço
veste velour carhartt
bañador neopreno mujer oysho
jogging fille 14 ans adidas
melhores marcas de mochilas masculinas
beistelltisch mit stauraum
nike air max 97 silber
adidas niño verde agua
béret a pompon bretelles uniforme
rompecabezas de obras de arte para arma
venta de bicicletas para ejercicio
sudadera nike vintage
lidl online dirndl
adidas noir doré
foot locker nike react element
filtre pour aspirateur samsung sc4780
adidas stabil x junior
nike air max de bebe
ReplyDeletesfera vestido flecos mostaza
filtre pour aspirateur samsung sc4780
tende doccia milano amazon
adidas superstar purple
jogging fille 14 ans adidas
af1 louis vuitton
sandália rasteira bottero
zapatillas bimba y lola outlet
chinelo slide da melissa
leggings mit spitzenabschluss
cartera levis hombre
ropa de crossfit nike
camisa da ferroviária
jersey rombos hm
gucci forocoches
sudadera nike vintage
shirt mit schnürung am ausschnitt
gants si assault factory pilot noir oakley
hama stiftplatte einhorn amazon
outlet nike floresta
sacoche lv district
nike hoodie xxl ebay
timberland herren 3 eye
kit citofono terraneo amazon
nike presto extreme pas cher
gucci handbags uk
nike huarache kobe bryant
tight leggings adidas
bolsas de deporte nike negra hombre grande
style année 80 femme
adidas personalised shoes
sandalia rafaela melo
survetement adidas homme militaire
vestido de niña rosa palo
adidas noir doré
adidas rock climbing
adidas boost 350 black
Thanks for sharing such a helpful, and understandable blog. I really enjoyed reading it.
ReplyDeleteRobots for kids
Robotic Online Classes
Robotics School Projects
Programming Courses Malaysia
Coding courses
Coding Academy
coding robots for kids
Coding classes for kids
Coding For Kids
Berkshire Clock Repair
ReplyDeleteJoseph Giret QC
Very wonderful informative article. I appreciated looking at your article. Very wonderful reveal. I would like to twit this on my followers. Many thanks!
ReplyDeletepolar covalent bond definition
ground state electron configuration
horizontal asymptote
associative learning
beneficence definition
shaping psychology definition
hyperpyrexia
costochondral separation
why has the kingdom protista been abandoned
analogous structures
I need to thank you for this very good read and i have bookmarked to check out new things from your post. Thank you very much for sharing such a useful article and will definitely save and revisit your site.
ReplyDeleteartificial intelligence internship | best final year projects for cse | internship certificate online | internship for mba finance students | internship meaning in tamil
شركة تنظيف افران بجدة
ReplyDeleteشركة عزل حراري بجدة
شركة تنظيف مسابح بجدة
شركة شفط بيارات بجدة
شركة رش حشرات بجدة
ReplyDeleteكشف تسربات المياه بالقطيف
كشف تسربات المياه بالخبر
كشف تسربات المياه بالدمام
كشف تسربات المياه بالاحساء
كشف تسربات المياه بالجبيل
شركة كشف تسربات المياه بالدمام
ReplyDeleteشركة تسليك مجاري بالدمام
شركة مكافحة حشرات بالدمام
شركة عزل اسطح بالدمام
شركة لمسات الابداع