My Life As A Blog

The Final Countdown?

leave a comment »

Michael Feathers’ thought-provoking post about deprecating the use of final (sealed in c#) has generated a good discussion – judging by the comments.  The discussion is about the use of final applied to classes and methods – not to instance variables (c# makes a distinction by using the readonly modifier for this usage.)
I rarely use final/sealed (I use final/readonly frequently.)  Final/sealed makes your classes much harder to test.  It can also make classes that use your classes harder to test.  And since you care if your code works or not, you’ll avoid final/sealed.  In addition to making testing more difficult, it conflicts with the open/closed principle – which may translate into increased maintenance issues.  It also suggests a lack of trust in those using your code (which in the case of the java.lang.string example posed by Michael Feathers, may be appropriate.)  I’d guess a lot of people choose final/sealed because they feel it will improve performance – I’d favour code that works (and the performance benefits may be insignificant.)


Written by remark

June 4, 2006 at 12:55 pm

Posted in Design, Software

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: