Last active
March 10, 2020 08:28
-
-
Save kunicmarko20/2d58b01a2620e1a45a83501337e472a0 to your computer and use it in GitHub Desktop.
When to use Final (from Slack)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rule #1: if you can’t think of a use-case for extending, make the class final. At the same time, make everything private instead of protected. | |
Rule #2: if your class is final, all public methods must be part of an interface that people can mock | |
Rule #3: prefer small, targeted interfaces instead of a compound interface | |
Rule #4: listen to your users, hear their concerns, work with them to avoid opening a final class | |
Rule #5: if a user has a legitimate use-case for extending a final class (as opposed to wrapping it), open it up and make necessary methods protected. Keep fields private. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment