Comment on design

?

-

I have a method

public void setGap(Gap gap) {
...
doLayout();
}


After calling the method I then do a static call to Gap.setXXX(..).
This means that I have to call setGap(gap) again because I want
"doLayout()" to be called since my setXXX(..) cannot call doLayout() due
to Gap not containing a reference to the class that has doLayout().

Is this good design?
 
S

Sonal

Why dont you define setGap as:

public void setGap(Gap gap, xx XXX){
....
gap.setXXX(XXX);
doLayout();

}
 
J

JScoobyCed

- said:
I have a method

public void setGap(Gap gap) {
...
doLayout();
}


After calling the method I then do a static call to Gap.setXXX(..). This
means that I have to call setGap(gap) again because I want "doLayout()"
to be called since my setXXX(..) cannot call doLayout() due to Gap not
containing a reference to the class that has doLayout().

Is this good design?

What about:
public interface GapListener {
public void updateGap();
}

public class GapManager implements GapListener {

public void setGap(Gap gap) {
// ...
gap.setGapListener(this);
doLayout();
}

public void updateGap() {
doLayout();
}
}

public class NewGap extends Gap {
// or maybe if you own the Gap object simply:
// public class Gap {

private static GapListener gapListener = null;

public static void setGapListener(GapListener gapListener) {
this.gapListener = gapListener;
}

public static void setXXX(XXX xxx) {
// do XXX stuff here
if(gapListener != null) {
gapListener.updateGap();
}
}
}
 
?

-

JScoobyCed said:
What about:
public interface GapListener {
public void updateGap();
}

public class GapManager implements GapListener {

public void setGap(Gap gap) {
// ...
gap.setGapListener(this);
doLayout();
}

public void updateGap() {
doLayout();
}
}

public class NewGap extends Gap {
// or maybe if you own the Gap object simply:
// public class Gap {

private static GapListener gapListener = null;

public static void setGapListener(GapListener gapListener) {
this.gapListener = gapListener;
}

public static void setXXX(XXX xxx) {
// do XXX stuff here
if(gapListener != null) {
gapListener.updateGap();
}
}
}


In my case, since Gap is my class, I can pass to its constructor, or in
your case the NewGap's constructor, a reference of the class that has
the doLayout() method.

I'm trying to avoid doing that because it looks out of place if you do a
new Gap(someClass, x, y) rather than a new Gap(x, y);

I'm wondering whether in the real world, the way I am going about doing
it is accepted - that is to leave it up to the user to call setGap(Gap
gap) again after he has set any new values of gap.
 
W

Wibble

- said:
In my case, since Gap is my class, I can pass to its constructor, or in
your case the NewGap's constructor, a reference of the class that has
the doLayout() method.

I'm trying to avoid doing that because it looks out of place if you do a
new Gap(someClass, x, y) rather than a new Gap(x, y);

I'm wondering whether in the real world, the way I am going about doing
it is accepted - that is to leave it up to the user to call setGap(Gap
gap) again after he has set any new values of gap.

I think the doLayout doesnt belong in setGap. What if you want to
change a few parameters before doLayout? You want to batch the
modifications and then doLayout.

Its unnatural to call setGap at the end to doLayout, just call doLayout.
 
J

Jesper Nordenberg

- said:
I have a method

public void setGap(Gap gap) {
...
doLayout();
}


After calling the method I then do a static call to Gap.setXXX(..).
This means that I have to call setGap(gap) again because I want
"doLayout()" to be called since my setXXX(..) cannot call doLayout() due
to Gap not containing a reference to the class that has doLayout().

Is this good design?

No.

/JN
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Top NOT top? 2
Survey details won't go through using php, ajax, Mysql 0
Tasks 1
School Project 1
Design for shared data 3
Please comment on this class hierarchy design 6
Help in hangman game 1
Void problem 1

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top