8000 Merge pull request #10 from github/jspahrsummers-patch-2 · smashcoding/swift-style-guide@ed32b74 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed32b74

Browse files
committed
Merge pull request github#10 from github/jspahrsummers-patch-2
Make as much of a class final as possible
2 parents bcb7586 + 8ad316b commit ed32b74

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,9 @@ struct Car: Vehicle {
180180
```
181181

182182
_Rationale:_ Value types are simpler, easier to reason about, and behave as expected with the `let` keyword.
183+
184+
#### Make classes `final` by default
185+
186+
Classes should start as `final`, and only be changed to allow subclassing if a valid need for inheritance has been identified. Even in that case, as many definitions as possible _within_ the class should be `final` as well, following the same rules.
187+
188+
_Rationale:_ Composition is usually preferable to inheritance, and opting _in_ to inheritance hopefully means that more thought will be put into the decision.

0 commit comments

Comments
 (0)
0