Getters and Setters in Swift
In Swift, you can store properties inside classes, structures, and enumerations. These properties are known as stored properties. As an example, a Person class could have a property called name.
In addition to stored properties, you can define proper...
artturijalli.hashnode.dev3 min read
Maxi Contieri
Software Engineer
Nice article!
IMO, Getters and setters are antipatterns and violate information Hiding and Encapsulation principles.
In your example. Code is magic and coupled and hides implicit conversions violating The Least Surprise Principle and Weight class is an example of an anemic object without real behavior.
All these problems are difficult to see in small programming snippets but cause lots of issues in big systems.