I know that the the final
keyword can be used to prevent you from extending a class. My question is When should a class be marked as final? Should every class be marked as final except for the ones that need to be extended?
Asked
Active
Viewed 37 times
0
-
Yes. If you are OCD, you should mark every class as final except for the ones that are intentionally made to be extended. Not everyone has that level of OCD. (Well, I do, but I'm probably not representative of a typical C++ developer.) – Eljay Jun 16 '18 at 17:36
-
1How do you know, when you write a class, that you will never want or need to extend it? I personally would only mark a class as `final` if a had a particular reason for doing so. Taking a step into th C# world for a moment, I think that `RSACryptoServiceProvider` in .Net might be marked as `final`, and there's no doubt a good (security) reason for that. – Paul Sanders Jun 16 '18 at 21:44