Skip to content

Instantly share code, notes, and snippets.

@kunicmarko20
Last active March 10, 2020 08:28
Show Gist options
  • Save kunicmarko20/2d58b01a2620e1a45a83501337e472a0 to your computer and use it in GitHub Desktop.
Save kunicmarko20/2d58b01a2620e1a45a83501337e472a0 to your computer and use it in GitHub Desktop.
When to use Final (from Slack)
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