java - Is creating a lot of private classes bad style? -
i doing project in java has lot of methods require multiple return objects. have keep creating private classes encapsulate return objects. objects make sense fontresult in code return font name , font size example creating new objects each return type require feels wrong , somehow trying circumvent how java should written. wrong or fine this? should structuring code in more of tell-dont-ask approach?
an example follows:
string test = "hello"; stringresult result = getinformation(test); int length = result.length; private stringresult getinformation(string test) { int length = test.length(); char firstchar = text.charat(0); } private class stringresult { int length; char firstchar; stringresult(int length, char firstchar) { this.length = length; this.firstchar = firstchar; } }
while necessary have "multiple return objects", sign indicating passing around information. possible situations:
you pass lot of data 1 object other objects tightly coupled -> should have 1 class.
you passing around information nobody uses -> erase it.
you passing around information between methods inside class should private field of class.
Comments
Post a Comment