Timeline for Can access modifiers be completely replaced with programming to interfaces?
Current License: CC BY-SA 4.0
5 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 19, 2022 at 19:34 | comment | added | gnasher729 | @OndrejBozek, in Swift such casts are safe and expected. You write “if let bar = foo as? Foo”. as? Means a cast that can fail and returns nil on failure, “if let” assigns an optional value to a non-optional that can only be used within the If statement. Very common pattern. Especially when you have a protocol (interface) “Any” which can be literally anything, so you must cast it. | |
| Oct 19, 2022 at 15:31 | comment | added | Greg Burghardt | @OndrejBozek: introducing a proxy class instead of properly using access modifiers would also be an anti-pattern. | |
| Oct 19, 2022 at 14:59 | comment | added | Ondrej Bozek | Good point, but this type cast is antipattern and would shine bright in review. It could be prohibited by encapsulating Impl class in Proxy class which implements only interface methods and forwards them to Impl. | |
| Oct 19, 2022 at 13:55 | history | edited | Greg Burghardt | CC BY-SA 4.0 | added 813 characters in body |
| Oct 19, 2022 at 13:49 | history | answered | Greg Burghardt | CC BY-SA 4.0 |