Skip to main content
Fix grammar, stream-of-concious style, minor formatting
Source Link

Using 'final' takes away freedom of others that want to use your code. 

If the code you write is only for you and will never be released to the public or a customer then you can do with your code what you want, of course. But otherwiseOtherwise, you prevent others from building upon your code. I've tooToo often have I had to work with an API that would have been easy to extend for my needs, but then the 'final'I was hindered me to do itby 'final'. 

Also, there is often code that should better notnot be made privateprivate, but protectedprotected. Sure, privateprivate means encapsulation"encapsulation" and hide things considered to be implementation details. But as an API programmer I might as well document the fact, hat that method xyzxyz is considered to be implementation detail and, thus, may be changed/deleted in future version. So everyone who will rely on such code in spite of the warning is doing it on his own risk. But he can actually do it and reuse (hopefully already tested) code and come up faster with a solution. 

Of course, if the API implementation is open source one can just remove the 'final' or make methods 'protected', but than you have changed the code and need to track your changes in form of patches. 

However, if the implementation is closed source you are left behind with finding a workaround or, in the worst case, with switching to another API with less restrictions regarding possibilities for customization/extension. 

Note that I don't find 'final' or 'private' are evil, but I think they are just used too often because the programmer didn't think about his code in terms of code reuse and extension.

Using 'final' takes away freedom of others that want to use your code. If the code you write is only for you and will never be released to the public or a customer then you can do with your code what you want, of course. But otherwise, you prevent others from building upon your code. I've too often had to work with an API that would have been easy to extend for my needs, but then the 'final' hindered me to do it. Also, there is often code that should better not be made private but protected. Sure, private means encapsulation and hide things considered to be implementation details. But as an API programmer I might as well document the fact, hat method xyz is considered to be implementation detail and, thus, may be changed/deleted in future version. So everyone who will rely on such code in spite of the warning is doing it on his own risk. But he can actually do it and reuse (hopefully already tested) code and come up faster with a solution. Of course, if the API implementation is open source one can just remove the 'final' or make methods 'protected', but than you have changed the code and need to track your changes in form of patches. However, if the implementation is closed source you are left behind with finding a workaround or, in the worst case, with switching to another API with less restrictions regarding possibilities for customization/extension. Note that I don't find 'final' or 'private' are evil, but I think they are just used too often because the programmer didn't think about his code in terms of code reuse and extension.

Using 'final' takes away freedom of others that want to use your code. 

If the code you write is only for you and will never be released to the public or a customer then you can do with your code what you want, of course. Otherwise, you prevent others from building upon your code. Too often have I had to work with an API that would have been easy to extend for my needs, but then I was hindered by 'final'. 

Also, there is often code that should better not be made private, but protected. Sure, private means "encapsulation" and hide things considered to be implementation details. But as an API programmer I might as well document the fact that method xyz is considered to be implementation detail and, thus, may be changed/deleted in future version. So everyone who will rely on such code in spite of the warning is doing it on his own risk. But he can actually do it and reuse (hopefully already tested) code and come up faster with a solution. 

Of course, if the API implementation is open source one can just remove the 'final' or make methods 'protected', but than you have changed the code and need to track your changes in form of patches. 

However, if the implementation is closed source you are left behind with finding a workaround or, in the worst case, with switching to another API with less restrictions regarding possibilities for customization/extension. 

Note that I don't find 'final' or 'private' are evil, but I think they are just used too often because the programmer didn't think about his code in terms of code reuse and extension.

Source Link
Jonny Dee
  • 957
  • 5
  • 12

Using 'final' takes away freedom of others that want to use your code. If the code you write is only for you and will never be released to the public or a customer then you can do with your code what you want, of course. But otherwise, you prevent others from building upon your code. I've too often had to work with an API that would have been easy to extend for my needs, but then the 'final' hindered me to do it. Also, there is often code that should better not be made private but protected. Sure, private means encapsulation and hide things considered to be implementation details. But as an API programmer I might as well document the fact, hat method xyz is considered to be implementation detail and, thus, may be changed/deleted in future version. So everyone who will rely on such code in spite of the warning is doing it on his own risk. But he can actually do it and reuse (hopefully already tested) code and come up faster with a solution. Of course, if the API implementation is open source one can just remove the 'final' or make methods 'protected', but than you have changed the code and need to track your changes in form of patches. However, if the implementation is closed source you are left behind with finding a workaround or, in the worst case, with switching to another API with less restrictions regarding possibilities for customization/extension. Note that I don't find 'final' or 'private' are evil, but I think they are just used too often because the programmer didn't think about his code in terms of code reuse and extension.