Eric Lefevre-Ardant on Java & Agile

March 12, 2007

YAGNI — You’re Aren’t Gonna Need It

Filed under: agile, java — Eric Lefevre-Ardant @ 1:19 pm

A couple of weeks ago, I started working on the objects that needed to be mapped onto the database. As I didn’t know what to do with each of them, I tried to keep things simple by mapping a foreign key into a Long.
A couple of days ago, I realized that this foreign key actually pointed to an object that was now available. Predictable enough, but was I right to map it to a simple Long before?

  • a Long was indeed the simplest thing I could do to design the link, as I didn’t need any other class to be designed to get my first class running
  • however, refactoring it into a real object is not easy; in fact, it is quite risky, as many places in the code will be changed (tests, Hibernate requests, equals() and hashcode() implementations). In fact, I tried and wasted a full day on it.
  • I think I’ll eventually have to remove it entirely before re-introducing the link between the two objects
  • Designing the first class as simply as I could was the right move. However, that’s not what I did; actually, I had added this foreign key because it was there, not because I needed it. If I had refrained from adding it as all, I wouldn’t have wasted time in trying to refactor it.

    All that because I didn’t apply YAGNI properly. A lesson to remember!

    Powered by WordPress