Advertisement
Guest User

might_be_your_solution

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