Interpreter (Chapter 25)
SOLUTION 25.1 | The following program will shut down all the machines that MachineLine controls, except for the unload buffer:
package com.oozinoz.robot.interpreter; import com.oozinoz.machine.*; public class ShowIf { public static void main(String[] args) { Context c = MachineLine.createContext(); Variable m = new Variable("m"); Constant ub = new Constant(c.lookup("UnloadBuffer1501")); Term t = new Equals(m, ub); IfCommand ic = new IfCommand( t, new NullCommand(), new ShutdownCommand(m)); ForMachines fc = new ForMachines(m, ic); fc.execute(c); } } The fc object is an interpreter; it interprets execute() to mean shut down all machines except the unload buffer. |
SOLUTION 25.2 | One solution is:
package com.oozinoz.robot.interpreter; ... |
Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.