Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. public class Top_Level_Class(){
  2. int x, y;
  3.  
  4. // gets user input which changes x, y;
  5. public void main(){
  6. int p, q, r, s;
  7. // compute p, q, r, s
  8. doA(p,q,r);
  9. doB(q,r,s);
  10. }
  11.  
  12. public void doA(int p, int q, int r){
  13. // do something that requires x,y and p, q, r
  14. }
  15.  
  16. public void doB(int q, int r, int s){
  17. // does something else that requires x, y and q, r, s
  18. }
  19. }
  20.  
  21. public class Top_Level_Class(){
  22. int x, y;
  23. SomeClass1a a = new SomeClass1a();
  24. SomeClass1a b = new SomeClass1b();
  25. // gets user input which changes x, y;
  26. public void main(){
  27. int p, q, r, s;
  28. // compute p, q, r, s
  29. a.doA(p,q,r);
  30. b.doB(q,r,s);
  31. }
  32.  
  33. public class SomeClass1a() { // in its own separate file
  34. public void doA(int p, int q, int r){
  35. // do something that requires x,y and p, q, r
  36. }
  37. }
  38.  
  39.  
  40. public class SomeClass1b() { // in its own separate file
  41. public void doB(int q, int r, int s){
  42. // does something else that requires x, y and q, r, s
  43. }
  44. }
  45.  
  46. a.set(x,y);
  47. a.doA(p,q,r);
  48.  
  49. // in the top level class:
  50. Container c = new Container(x,y);
  51. a.setContainer(c);
  52. b.setContainer(c);
  53.  
  54. class Container{
  55.  
  56. //eventually provides setters and getters
  57. public float x;
  58. public float y;
  59. //------------
  60.  
  61. private static Container instance = null;
  62. private void Container(){
  63.  
  64. }
  65. public static Container getInstance(){
  66. if(instance==null){
  67. instance = new Container();
  68. }
  69. return instance;
  70. }
  71. }
  72.  
  73. Container.getInstance().x = 3;
  74. temp = Container.getInstance().x;
  75.  
  76. public class SubClass1a() { // in its own separate file
  77. public void doA(Top_Level_Class caller, int p, int q, int r){
  78. // do something that requires x,y and p, q, r
  79. // **to get x use the expression term caller.getX() and caller.getY()**
  80. }
  81. }
  82.  
  83. public class Top_Level_Class(){
  84. Container container = new Container(x, y, p, q, r, s);
  85. SubClass1a a = new SubClass1a(container);
  86. SubClass1a b = new SubClass1b(container);
  87. // gets user input which changes x, y using container's getters and setters
  88. public void main(){
  89. // compute and set p, q, r, s
  90. a.doA();
  91. b.doB();
  92. }
  93.  
  94. public class SubClass1a(Container c) { // in its own separate file
  95. public void doA(c.getX, c.getY, c.getP, c.getQ, c.getR){
  96. // do something that requires x, y, p, q, and r
  97. }
  98. }
  99.  
  100. public class SubClass1b(Container c) { // in its own separate file
  101.  
  102. public void doB(c.getX, c.getY, c.getQ, c.getR, c.getS){
  103. // does something else that requires x, y, q, r, and s
  104. }
  105. }
  106.  
  107. public class Container(x, y, p, q, r, s) {
  108. //getters and setters for all variables
  109. }
  110.  
  111. public class Main {
  112. public static void main(String... args) {
  113. MutableDataContainer m = new MutableDataContainer();
  114. ImmutableDataContainer i = computeImmutableData();
  115. new ADoer().doA(m, i);
  116. new BDoer().doB(m, i);
  117. }
  118. ...
  119. }
  120.  
  121. class MutableDataContainer {
  122. private int x, y;
  123. ... // getters and setters below
  124. }
  125.  
  126. class ImmutableDataContainer {
  127. private final int p, q, r, s;
  128. ... // getters below
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement