Alex Rivera | Logout

Keeping track of utility classes

Asked 2011-04-11T17:52:57.780
19

I've recently been more and more frustrated with a problem I see emerging in my projects code-base.

I'm working on a large scale java project that has >1M lines of code. The interfaces and class structure are designed very well and the engineers writing the code are very proficient. The problem is that in an attempt to make the code cleaner people write Utility classes whenever they need to reuse some functionality, as a result over time and as the project grows more and more utility methods crop up. However, when the next engineer comes across the need for the same functionality he has no way of knowing that someone had already implemented a utility class (or method) somewhere in the code and implements another copy of the functionality in a different class. The result is a lot of code duplication and too many utility classes with overlapping functionality.

Are there any tools or any design principles which we as a team can implement in order to prevent the duplication and low visibility of the utility classes?

Example: engineer A has 3 places he needs to transform XML to String so he writes a utility class called XMLUtil and places a static toString(Document) method in it. Engineer B has several places where he serializes Documents into various formats including String, so he writes a utility class called SerializationUtil and has a static method called serialize(Document) which returns a String.

Note that this is more than just code-duplication as it is quite possible that the 2 implementations of the above example are different (say one uses transformer API and the other uses Xerces2-J) so this can be seen as a "best-practices" problem as well...

Update: I guess I better describe the current environment we develop in. We use Hudson for CI, Clover for code coverage and Checkstyle for static code analysis. We use agile development including dail

Edit
Report

1 Answer

1
  1. Team communication (shout out "hey does someone have a Document toString?")
  2. Keep utility classes to an absolute minimum and restrict them to a single namespace
  3. Always think: how can I do this with an object. In your example, I would extend the Document class and add those toString and serialize methods to it.
answered 2011-04-11T18:28:49.173

Your Answer