Advertisement
Guest User

my_solution

a guest
Apr 30th, 2013
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. /* Create a new class called AParams */
  2. public class AParams{
  3.     AParams();
  4.     get/setArgument(String argument);
  5.     get/setOtherArgument(String argument);
  6. }
  7. public class AFactory {
  8.     public A create(String name){/*Create the correct A*/}
  9. }
  10.  
  11. public abstract class A {
  12.     public abstract void doStuff(AParams argument);
  13. }
  14.  
  15. public class A1 extends A{
  16.     public void doStuff(AParams argument){/*some usage of argument*/}
  17. }
  18. .
  19. .
  20. .
  21. public class AN extends A{
  22.     public void doStuff(AParams argument){/*some usage of argument*/}
  23. }
  24.  
  25. public class B extends A{
  26.     public void doStuff(AParams argument){
  27.         /*I need otherArgument too!
  28.          * And it's not in the UserInput class which I
  29.          * cannot change/inherit/modify in any way :|
  30.         */
  31.     }
  32. }
  33.  
  34. public class Interpreter{
  35.     Interpreter(){}
  36.     public Stuff interpret(UserInput userInput)
  37.     /* read the user input and do MANY things with the input
  38.      * one of them  might be calling AFactory.create
  39.      * and in the end Runner will get its A instances
  40.     */
  41. }
  42.  
  43. public class Runner{
  44.     public static void run(){
  45.         /* Runner needs otherArgument which B needs but
  46.          * for something else
  47.          */
  48.         for(String argument : listOfArguments){
  49.             for(A actualA : listOfA)
  50.                 AParams params = new AParams();
  51.                 params.setArgument(argument);
  52.                 params.setOtherArgument(otherArgument);
  53.                 actualA.doStuff(params);
  54.         }
  55.     }
  56. }
  57.  
  58. public class EntryPoint{
  59.     /* Has both UserInput and otherArgument
  60.      * it calls the interpreter.
  61.     */
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement