Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Top_Level_Class(){
- int x, y;
- // gets user input which changes x, y;
- public void main(){
- int p, q, r, s;
- // compute p, q, r, s
- doA(p,q,r);
- doB(q,r,s);
- }
- public void doA(int p, int q, int r){
- // do something that requires x,y and p, q, r
- }
- public void doB(int q, int r, int s){
- // does something else that requires x, y and q, r, s
- }
- }
- public class Top_Level_Class(){
- int x, y;
- SomeClass1a a = new SomeClass1a();
- SomeClass1a b = new SomeClass1b();
- // gets user input which changes x, y;
- public void main(){
- int p, q, r, s;
- // compute p, q, r, s
- a.doA(p,q,r);
- b.doB(q,r,s);
- }
- public class SomeClass1a() { // in its own separate file
- public void doA(int p, int q, int r){
- // do something that requires x,y and p, q, r
- }
- }
- public class SomeClass1b() { // in its own separate file
- public void doB(int q, int r, int s){
- // does something else that requires x, y and q, r, s
- }
- }
- a.set(x,y);
- a.doA(p,q,r);
- // in the top level class:
- Container c = new Container(x,y);
- a.setContainer(c);
- b.setContainer(c);
- class Container{
- //eventually provides setters and getters
- public float x;
- public float y;
- //------------
- private static Container instance = null;
- private void Container(){
- }
- public static Container getInstance(){
- if(instance==null){
- instance = new Container();
- }
- return instance;
- }
- }
- Container.getInstance().x = 3;
- temp = Container.getInstance().x;
- public class SubClass1a() { // in its own separate file
- public void doA(Top_Level_Class caller, int p, int q, int r){
- // do something that requires x,y and p, q, r
- // **to get x use the expression term caller.getX() and caller.getY()**
- }
- }
- public class Top_Level_Class(){
- Container container = new Container(x, y, p, q, r, s);
- SubClass1a a = new SubClass1a(container);
- SubClass1a b = new SubClass1b(container);
- // gets user input which changes x, y using container's getters and setters
- public void main(){
- // compute and set p, q, r, s
- a.doA();
- b.doB();
- }
- public class SubClass1a(Container c) { // in its own separate file
- public void doA(c.getX, c.getY, c.getP, c.getQ, c.getR){
- // do something that requires x, y, p, q, and r
- }
- }
- public class SubClass1b(Container c) { // in its own separate file
- public void doB(c.getX, c.getY, c.getQ, c.getR, c.getS){
- // does something else that requires x, y, q, r, and s
- }
- }
- public class Container(x, y, p, q, r, s) {
- //getters and setters for all variables
- }
- public class Main {
- public static void main(String... args) {
- MutableDataContainer m = new MutableDataContainer();
- ImmutableDataContainer i = computeImmutableData();
- new ADoer().doA(m, i);
- new BDoer().doB(m, i);
- }
- ...
- }
- class MutableDataContainer {
- private int x, y;
- ... // getters and setters below
- }
- class ImmutableDataContainer {
- private final int p, q, r, s;
- ... // getters below
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement