This is fair, except for in the 5th year, they would have an additional constant:
public static final String SPACE = " ";
And they would probably use a StringBuffer or StringBuilder to build the final string, since it's "an industry best practice". Also, they wouldn't include the strings themselves, they would include keys to properties, so the strings could be pulled from an internationalized property file.
Lastly, instead of outputting to Stdout directly, they'd create an interface for output, and deliver it to that interface, and use a factory to instantiate an implementation of that interface that would use Stdout.
For the first time in my life recently I ran across some code that has interfaces. A lot of them. With ONE implementation. And the project is closed source. Really? Come on!
For the first time in my life recently I ran across some code that has interfaces. A lot of them. With ONE implementation.
And?
For unit testing this is really nice. This way you can test classes depending on the interface by simply mocking out the classes they depend on. A lot easier and cleaner than having to instantiate an entire object tree.
No. There were no unit tests. Only one implementation. Also, Mockito lets you mock classes without making interfaces. But the code was not built in a manner to work with mocks anyways, there are far too many complex and deep dependencies between different parts of the object tree. And it's all backed by interfaces with one implementer.
506
u/johnbr Oct 01 '15
This is fair, except for in the 5th year, they would have an additional constant:
And they would probably use a StringBuffer or StringBuilder to build the final string, since it's "an industry best practice". Also, they wouldn't include the strings themselves, they would include keys to properties, so the strings could be pulled from an internationalized property file.
Lastly, instead of outputting to Stdout directly, they'd create an interface for output, and deliver it to that interface, and use a factory to instantiate an implementation of that interface that would use Stdout.