Skip to main content
Tweeted twitter.com/StackProgrammer/status/754094332416815108

I am working on a UI code where I have an Action class, something like this -

    public class MyAction extends Action {
      public MyAction() {
          setText("My Action Text");
          setToolTip("My Action Tool tip");
          setImage("Some Image");
      }
    }

When this Action class was created, it was pretty much assumed that the Action class won't be customizable (in a sense - its text, tooltip or image will be not be changed anywhere in the code). Of lateNow, now we are in need of changing the action text at some location in code. So, I suggested my co-worker to remove the hardcoded action text from the constructor and accept it as an argument, so that everybody is forced to pass the action text. Something like this code below -

public class MyAction extends Action {
    public MyAction(String actionText) {
        setText(actionText);
        setTooltip("My Action tool tip"); 
        setImage("My Image"); 
    }
}

He, however, thinks that since setText() method belongs to base class it can be flexibly used to pass the action text wherever action instance is created. That way, there is no need to change the existing MyAction class. So his code would look something like this.

MyAction action = new MyAction(); //this creates action instance with the hardcoded text
action.setText("User required new action text"); //overwrite the existing text.

I am not sure if that is a correct way to deal with problem. I think in above mentioned case user is anyway going to change the text, so why not force him while constructing the action? The only benefit I see with the original code is that user can create Action class without much thinking about setting text.

I am working on a UI code where I have an Action class, something like this -

    public class MyAction extends Action {
      public MyAction() {
          setText("My Action Text");
          setToolTip("My Action Tool tip");
          setImage("Some Image");
      }
    }

When this Action class was created it was pretty much assumed that the Action class won't be customizable (in a sense - its text, tooltip or image will be not be changed anywhere in the code). Of late, now we are in need of changing the action text at some location in code. So I suggested my co-worker to remove the hardcoded action text from the constructor and accept it as an argument, so that everybody is forced to pass the action text. Something like this code below -

public class MyAction extends Action {
    public MyAction(String actionText) {
        setText(actionText);
        setTooltip("My Action tool tip"); 
        setImage("My Image"); 
    }
}

He however thinks that since setText() method belongs to base class it can be flexibly used to pass the action text wherever action instance is created. That way, there is no need to change the existing MyAction class. So his code would look something like this.

MyAction action = new MyAction(); //this creates action instance with the hardcoded text
action.setText("User required new action text"); //overwrite the existing text.

I am not sure if that is a correct way to deal with problem. I think in above mentioned case user is anyway going to change the text, so why not force him while constructing the action? The only benefit I see with the original code is that user can create Action class without much thinking about setting text.

I am working on a UI code where I have an Action class, something like this -

public class MyAction extends Action {
    public MyAction() {
        setText("My Action Text");
        setToolTip("My Action Tool tip");
        setImage("Some Image");
    }
}

When this Action class was created, it was pretty much assumed that the Action class won't be customizable (in a sense - its text, tooltip or image will be not be changed anywhere in the code). Now, we are in need of changing the action text at some location in code. So, I suggested my co-worker to remove the hardcoded action text from the constructor and accept it as an argument, so that everybody is forced to pass the action text. Something like this code below -

public class MyAction extends Action {
    public MyAction(String actionText) {
        setText(actionText);
        setTooltip("My Action tool tip"); 
        setImage("My Image"); 
    }
}

He, however, thinks that since setText() method belongs to base class it can be flexibly used to pass the action text wherever action instance is created. That way, there is no need to change the existing MyAction class. So his code would look something like this.

MyAction action = new MyAction(); //this creates action instance with the hardcoded text
action.setText("User required new action text"); //overwrite the existing text.

I am not sure if that is a correct way to deal with problem. I think in above mentioned case user is anyway going to change the text, so why not force him while constructing the action? The only benefit I see with the original code is that user can create Action class without much thinking about setting text.

added 10 characters in body
Source Link
gnat
  • 20.5k
  • 29
  • 117
  • 309

I am working on a UI code where I have an ActionAction class, something like this -

    public class MyAction extends Action {
      public MyAction() {
          setText("My Action Text");
          setToolTip("My Action Tool tip");
          setImage("Some Image");
      }
    }

When this Action class was created it was pretty much assumed that the ActionAction class wontwon't be customizable (in a sense  - its text, tooltip or image will be not be changed anywhere in the code). Of late, now we are in need of changing the action text at some location in code. So I suggested my co-worker to remove the hardcoded action text from the constructor and accept it as an argument, so that everybody is forced to pass the action text. Something like this code below -

public class MyAction extends Action {
    public MyAction(String actionText) {
        setText(actionText);
        setTooltip("My Action tool tiptip"); 
        setImage("My Image"); 
    }
}

He however thinks that since setText()setText() method belongs to base class. It it can be flexibly used to pass the action text wherever action instance is created. That way, there is no need to change the existing MyActionMyAction class. So his code would look something like this.

MyAction action = new MyAction(); //this creates action instance with the hardcoded text
action.setText("User required new action text"); //overwrite the exisitngexisting text.

I am not sure if that is a correct way to deal with problem. I think in above mentioned case user is anyway going to change the text, so why not force him while constructing the action.? The only benefit I see with the original code is that user can create Action class without much thinking about setting text.

I am working on a UI code where I have an Action class, something like this -

    public class MyAction extends Action {
      public MyAction() {
          setText("My Action Text");
          setToolTip("My Action Tool tip");
          setImage("Some Image");
      }
    }

When this Action class was created it was pretty much assumed that the Action class wont be customizable (in a sense- its text, tooltip or image will be not be changed anywhere in the code). Of late, now we are in need of changing the action text at some location in code. So I suggested my co-worker to remove the hardcoded action text from the constructor and accept it as an argument, so that everybody is forced to pass the action text. Something like this code below -

public class MyAction extends Action {
    public MyAction(String actionText) {
        setText(actionText);
        setTooltip("My Action tool tip); 
        setImage("My Image"); 
    }
}

He however thinks that since setText() method belongs to base class. It can be flexibly used to pass the action text wherever action instance is created. That way, there is no need to change the existing MyAction class. So his code would look something like this.

MyAction action = new MyAction(); //this creates action instance with the hardcoded text
action.setText("User required new action text"); //overwrite the exisitng text.

I am not sure if that is a correct way to deal with problem. I think in above mentioned case user is anyway going to change the text, so why not force him while constructing the action. The only benefit I see with the original code is that user can create Action class without much thinking about setting text.

I am working on a UI code where I have an Action class, something like this -

    public class MyAction extends Action {
      public MyAction() {
          setText("My Action Text");
          setToolTip("My Action Tool tip");
          setImage("Some Image");
      }
    }

When this Action class was created it was pretty much assumed that the Action class won't be customizable (in a sense  - its text, tooltip or image will be not be changed anywhere in the code). Of late, now we are in need of changing the action text at some location in code. So I suggested my co-worker to remove the hardcoded action text from the constructor and accept it as an argument, so that everybody is forced to pass the action text. Something like this code below -

public class MyAction extends Action {
    public MyAction(String actionText) {
        setText(actionText);
        setTooltip("My Action tool tip"); 
        setImage("My Image"); 
    }
}

He however thinks that since setText() method belongs to base class it can be flexibly used to pass the action text wherever action instance is created. That way, there is no need to change the existing MyAction class. So his code would look something like this.

MyAction action = new MyAction(); //this creates action instance with the hardcoded text
action.setText("User required new action text"); //overwrite the existing text.

I am not sure if that is a correct way to deal with problem. I think in above mentioned case user is anyway going to change the text, so why not force him while constructing the action? The only benefit I see with the original code is that user can create Action class without much thinking about setting text.

clarified question tags from comments; added 4 characters in body
Source Link
gnat
  • 20.5k
  • 29
  • 117
  • 309

I am working on a UI code where I have an Action class, something like this -

    public class MyAction extends Action {
      public MyAction() {
          setText("My Action Text");
          setToolTip("My Action Tool tip");
          setImage("Some Image");
      }
    }

When this Action class was created it was pretty much assumed that the Action class wont be customizable (in a sense- its text, tooltip or image will be not be changed anywhere in the code). Of late, now we are in need of changing the action text at some location in code. So I suggested my co-worker to remove the hardcoded action text from the constructor and accept it as an agrumentargument, so that everybody is forced to pass the action text. Something like this code below -

public class MyAction extends Action {
    public MyAction(String actionText) {
        setText(actionText);
        setTooltip("My Action tool tip); 
        setImage("My Image"); 
    }
}

He however thinks that since setText() method belongs to base class. It can be flexibly used to pass the action text wherever action instance is created. That way, there is no need to change the existing MyAction class. So his code would look something like this.

MyAction action = new MyAction(); //this creates action instance with the hardcoded text
action.setText("User required new action text"); //overwrite the exisitng text.

I am not sure if that is a correct way to deal with problem. I think in above mentioned case user is anyway going to change the text, so why not force him while constructing the action. The only benefit I see with the original code is that user can create Action class without much thinking about setting text.

I am working on a UI code where I have an Action class, something like this -

    public class MyAction extends Action {
      public MyAction() {
          setText("My Action Text");
          setToolTip("My Action Tool tip");
          setImage("Some Image");
      }
}

When this Action class was created it was pretty much assumed that the Action class wont be customizable (in a sense- its text, tooltip or image will be not be changed anywhere in the code). Of late, now we are in need of changing the action text at some location in code. So I suggested my co-worker to remove the hardcoded action text from the constructor and accept it as an agrument, so that everybody is forced to pass the action text. Something like this code below -

public class MyAction extends Action {
    public MyAction(String actionText) {
        setText(actionText);
        setTooltip("My Action tool tip); 
        setImage("My Image"); 
    }
}

He however thinks that since setText() method belongs to base class. It can be flexibly used to pass the action text wherever action instance is created. That way, there is no need to change the existing MyAction class. So his code would look something like this.

MyAction action = new MyAction(); //this creates action instance with the hardcoded text
action.setText("User required new action text"); //overwrite the exisitng text.

I am not sure if that is a correct way to deal with problem. I think in above mentioned case user is anyway going to change the text, so why not force him while constructing the action. The only benefit I see with the original code is that user can create Action class without much thinking about setting text.

I am working on a UI code where I have an Action class, something like this -

    public class MyAction extends Action {
      public MyAction() {
          setText("My Action Text");
          setToolTip("My Action Tool tip");
          setImage("Some Image");
      }
    }

When this Action class was created it was pretty much assumed that the Action class wont be customizable (in a sense- its text, tooltip or image will be not be changed anywhere in the code). Of late, now we are in need of changing the action text at some location in code. So I suggested my co-worker to remove the hardcoded action text from the constructor and accept it as an argument, so that everybody is forced to pass the action text. Something like this code below -

public class MyAction extends Action {
    public MyAction(String actionText) {
        setText(actionText);
        setTooltip("My Action tool tip); 
        setImage("My Image"); 
    }
}

He however thinks that since setText() method belongs to base class. It can be flexibly used to pass the action text wherever action instance is created. That way, there is no need to change the existing MyAction class. So his code would look something like this.

MyAction action = new MyAction(); //this creates action instance with the hardcoded text
action.setText("User required new action text"); //overwrite the exisitng text.

I am not sure if that is a correct way to deal with problem. I think in above mentioned case user is anyway going to change the text, so why not force him while constructing the action. The only benefit I see with the original code is that user can create Action class without much thinking about setting text.

Source Link
zswap
  • 163
  • 1
  • 1
  • 6
Loading