JS Ext

Monday, April 22, 2013

Overly Objective

I have been analyzing some code at work.  It is part of a project that nobody wants to touch.  Nobody wants to touch it because it has a history of being poorly designed.  I'm starting a series of posts where I discuss some of the design problems.

This project is an example of objects run a muck.  It is written in Java, which has a common base object: java.lang.Object.  The designer decided that he wanted his own base object.  I will call is MyObject.  The 'My' is a generic prefix.  He used the acronym for the name of the project.  Every single object had this prefix.  So, MyObject implemented java.lang.Comparable and had an abstract method called getSortName().  The compareTo() method just did a string sort over the result of getSortName().  This allowed the developer never have to write a Comparator class.  He could just implement the getSortName() and the object was automatically sortable.  This doesn't sound too bad, exception every single object eventually extended MyObject; whether it was sortable or not.  It also gets abused later.

Every single concept got its own object.  There was a series of name objects.  For example, there was a class called MyAppName that had a sole member attribute called name.  The only class that directly used it was a class called MyApp.  The name of the app was stored in the MyAppName object.  So, if you had a reference to MyApp and you wanted to get the name of the app, you had to call myApp.getName().getName().

This absurdity becomes the most apparent with the MyRevision class.  This class stores the revision number of something.  The revision number is a positive integer.  The maximum revision number ever seen was around 300, but in theory it could go higher.  Personally, I would use an int.  Some people don't like primitives, though.  Therefore, MyRevision stored the revision number as a string!  This begs the question: how do you sort it?  Remember MyObject and its getSortName() method?  MyRevision.getSortName() returns the revision number as a '0' padded string with a length of 8.  Sorting problem solved.  Performance....who needs that!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.