Client

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Client as PDF for free.

More details

  • Words: 487
  • Pages: 8
Client.java /** * */ /** * @author Mukesh * @generated "UML to Java V5.0 (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)" */ public class Client { }

Command.java public interface Command { public void execute(); }

ConcreteCommand.java

/** * */ /** * @author Mukesh * @generated "UML to Java V5.0 (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)" */ public class ConcreteCommand { }

Light.java public class Light { private Object Location; public Object getLocation() { return Location; } public void setLocation(Object theLocation) { Location = theLocation; } private Boolean LightState; public Boolean getLightState() { return LightState; } public void setLightState(Boolean theLightState) { LightState = theLightState; } public Light(String location) { this.Location = location; } public Light() { } public void On() { if (LightState == false) { System.out.println("The light is now on for:" + this.Location); LightState = true; } else System.out.println("The light is already on for:" + this.Location); } public void Off() { if (LightState == true) { System.out.println("The light is now off for:" + Location); } else System.out.println("The light is already off for:" + Location); } }

LightOff.java public class LightOff implements Command { /** * @generated "UML to Java V5.0 (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)" */ public Light receiver; /** * @return the receiver * @generated "UML to Java V5.0 (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)" */ public Light getReceiver() { // begin-user-code return receiver; // end-user-code } /** * @param theReceiver the receiver to set * @generated "UML to Java V5.0 (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)" */ public void setReceiver(Light theReceiver) { // begin-user-code receiver = theReceiver; // end-user-code } /** * @generated "Command (com.ibm.xtools.patterns.content.gof.behavioral.command.CommandPattern)" */ public LightOff(Light receiver) { // begin-user-code this.receiver = receiver; }

// end-user-code

/** * @generated "Command (com.ibm.xtools.patterns.content.gof.behavioral.command.CommandPattern)" */ public void execute() { // begin-user-code // begin-user-code// TODO: Invoke methods in receiver to carry out the request. throw new java.lang.UnsupportedOperationException();

} }

// end-user-code // end-user-code

Lighton.java public class LightOn implements Command { public Light receiver; public Light getReceiver() { return receiver; } public void setReceiver(Light theReceiver) { receiver = theReceiver; } public LightOn(Light receiver) { this.receiver = receiver; }

}

public void execute() { receiver.On(); }

Person.jva public class Person { public void invoke() { Light aReceiver = new Light(); LightOn aConcreteCommand = new LightOn(aReceiver); Switch anInvoker = new Switch(); anInvoker.setCommand(aConcreteCommand); anInvoker.invokeCommand(); } public static void main(String[] args) { Light aReceiver = new Light("My Room"); LightOn aconcom = new LightOn(aReceiver); LightOff bconcom = new LightOff(aReceiver); Switch anInvoker = new Switch(); anInvoker.setFlipUp(aconcom); anInvoker.setFlipDown(bconcom); for (int i = 0; i < args.length; i++) { if (args[i].equalsIgnoreCase("on")) anInvoker.FlipUp(); else if (args[i].equalsIgnoreCase("off")) anInvoker.FlipDown(); } } }

Switch.java public class Switch { private Command command; public Command getCommand() { return command; } private Command FlipDown; private Command FlipUp; public Command getFlipDown() { return FlipDown; } public void setFlipDown(Command theFlipDown) { FlipDown = theFlipDown; } public Command getFlipUp() { return FlipUp; } public void setFlipUp(Command theFlipUp) { FlipUp = theFlipUp; } public void FlipDown() { FlipDown.execute(); } public void FlipUp() { FlipUp.execute(); } public void setCommand(Command theCommand) { this.command = theCommand; } public void invokeCommand() { this.command.execute(); } }

Related Documents

Client
June 2020 33
Client
May 2020 19
Client Roster
December 2019 24
Client Server
May 2020 26
Significant Client
May 2020 12
Client Advantage
November 2019 16