The MTA (aka the NY transit people, aka the only people I know who actually use a .info TLD) hate me. The past few weeks, the train I take home (the L) train has not been running between midnight and 5am. For those who know me, you can understand that this seriously cramps my style. Bastards!
But now, to rub salt in an already painful wound, they've decided not to run the L train all weekend. So I'm essentially stranded in Brooklyn unless I want to spend an altogether rediculous amount of time taking the G and J trains. Grr!
I bought this a little while after GUADEC and being inspired by pvanhoof. It's pretty good. I've actually used most of the patterns in some way, shape or form before but it's good to put a name to them and get the formal definition in my head. However...
So I touched on this a while earlier but today my hatred for UnsupportedOperationException got some more fuel when I was reading the design patterns book.
In the composite pattern they actually recommend using this exception so an implementation can avoid implementing some of the methods from the interface. They do mention that not implementing some of the interface methods is bad, it's a tradeoff, etc. Fine.
What's evil about UnsupportedOperationException is that it's unchecked. Meaning the compiler doesn't warn you about it if you don't try to catch it. So here you are, coding against some interface and unbeknownst to you some of the methods are just going to bail on you and your app will crash, and you would never know that this will happen by looking at the interface specification or from compiler warnings. Lovely!
Please, people: stop using UnsupportedOperationException! If you really need to leave some interface elements unimplemented make your own checked exception like UnimplementedException or something and explicitly indicate which interface elements are optional by using throws in the declaration.
Unchecked exceptions should really only be for serious runtime errors, like NullPointerException, ArrayIndexOutOfBoundsException or ClassNotFoundException. IMO UnsupportedOperationException is a gigantic hack that should never have existed in the first place. And now we're all screwed by it.. sigh.