What's the downside of instantiating an instance of itself in a static method and then working with this object instead of doing everything statically?
Say I have a class like this:
public class MyClass {
private String foo;
private String bar;
private MyClass(String foo, String bar) {
this.foo = foo;
this.bar = bar;
}
public static String concat(String foo, String bar) {
MyClass myClass = new MyClass(foo, bar);
return myClass.concatStrings();
}
private String concatStrings() {
return foo + bar;
}
}
The benefit of this pattern is that I don't have to pass around the input parameters to various private methods. The only bad thing I can think of, is that it might be a performance issue to create an object that I don't really need. But with this very simple example I only notice a real difference (in a quick junit test) with a LOT of iterations (i.e. >=10^8) compared to a simple static class like this:
public class MyStaticClass {
public static String concat(String foo, String bar) {
return foo + bar;
}
}
Are there any other arguments for or against this pattern?