OCPJP 6 86%
OCA7
ankita modi. wrote:Why we do explicit abstract declaration of an interface ?
OCPJP 6 86%
Nikhil Sagar wrote:Is it correct ? or i missed anything.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
PS: Two great cases in point are BigDecimal and BigInteger: Josh Bloch (who wrote them) freely admits that they should have been made final; but, once published, there was no way it could be added without compromising existing code. Therefore, in theory, you should check all BigInteger's received from an untrusted source to make sure that they're not some naughty subclass.
Personally, I always make BOTH (class and method defintiions) final by default; because you can always undo that decision. What you can't do is add the final keyword anywhere after a class is published.
OCPJP 6 86%
Nikhil Sagar wrote:This is a good idea but if you are in your testing or developing phase.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:Either a class already has a subclass or it doesn't. If it doesn't, leave it (and all its methods) final.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Nikhil Sagar wrote:This is a good idea but if you are in your testing or developing phase.
I'm not quite sure why that should make a difference.
OCPJP 6 86%
Nikhil Sagar wrote:And i always thought that making a class final means that developer is quite sure that his class is perfectly complete class and there is no need to subclass it.
I am still not sure that after deployment making such a decision is good or not because i think many existing users of this class can complain about it that Why now ?? Why did you make it final at deployment time if you were not sure, that could make my code less complex.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Nikhil Sagar wrote:And i always thought that making a class final means that developer is quite sure that his class is perfectly complete class and there is no need to subclass it.
I am still not sure that after deployment making such a decision is good or not because i think many existing users of this class can complain about it that Why now ?? Why did you make it final at deployment time if you were not sure, that could make my code less complex.
You certainly have a point; I'm just not sure it's good enough to warrant compromising good practise for.
1. Hopefully, there's some mechanism in place to provide feedback from your users; and if people find your class difficult to use specifically because it's final, you can always change your mind later on. What you can't do, as I said above, is make a non-final class final after the fact.
2. There are other ways of extending classes than just inheritance - the main one being composition - and they're often preferable to strict hierarchies.
And on the subject of point 2, I can think of one example of a class that shouldn't be final, and neither should it's methods: a reusable "forwarder" or "wrapper" class. For example, I have a CharsWrapper class that I use for wrapping CharSequence's (which include Strings), and it looks like:Now it doesn't look like much on its own; but I've used it as a base for creating a couple of useful (and final ) subclasses, including a "fast search" class that uses the Horspool algorithm.
Winston
OCPJP 6 86%
OCPJP 6 86%
Nikhil Sagar wrote:Winson, please tell me just one last time that is it a good practice you are talking about because you know you can't argue much with Project managers ?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
My suggestion: If your manager is a techie (or ex-techie), bang off a printout of this discussion and show it to him/her and see what they say. At the very least they'll then know that your misgivings aren't simply "gut" feeling, and based on something rational.
My approach to the final keyword can be likened to number 2: I don't let anyone extend my classes or override my methods unless I decide so. It's simple, and I'm God - and that's the way I like it.
OCPJP 6 86%