|
Prev: can i learn OOD without any procedural 1st
Next: Is 'Final' for classes and methods a good feature or somethingthat should be eliminated?
From: Michael Feathers on 20 Feb 2007 09:22 Funny thing about *final*. It looks like a great feature. You get to decide whether a class can have subclasses or whether a method can be overridden, but now I think it is too easy to abuse. Sure, if you have control over all of your code, you can make things *final* and remove *final* when it gets in the way, but if you develop code for someone else you can easily put them in a situation where it is hard or impossible to write unit tests for particular areas of code. Classic example: You have a class A from Vendor X and it has 15 methods. One of your classes, B, uses it and one of the methods that it uses has some sideffect you wouldn't like to see happen in a test. You'd like to mock out that method on A, and you could by subclassing A and overriding the method, but if Vendor X made A or that method of A final, your options are limited. ---- Michael Feathers www.objectmentor.com michaelfeathers.typepad.com author of: Working Effectively with Legacy Code (Prentice Hall 2005) |