📗 Learn from the written tutorial 👇👇
https://resocoder.com/dart-sum-types-...
👨💻 Do you write good code? Find out now!
https://resocoder.com/good-code-quiz
Handling poorly documented edge cases is tough. Using nulls to represent "no value" and then having to check for nulls all over the place is bad. Remembering all the possible subtypes of a base class is hard. All in all, relying on you "remembering things" is a recipe for disaster.
That's why you should model your domain in such a way that wrongly written code doesn't even compile. That's right, you can actually prevent many run-time crashes and get notified about errors in the code editor before hitting the run button.
We're going to demonstrate all of the above by building a small part of a fake CRM (customer relationship management) responsible for sending out physical letters. We support only customers from the USA and from Canada. As you know, one component of a postal address is the state (e.g. Florida) for the US, or the province (e.g. Ontario) for Canada. It's precisely on the state or province, where you'll learn how to design with types.
We will move from the most naive (and sadly common) implementation to the most robust one. The robust implementation will require us to use some sort of a sum type (a.k.a. sealed classes in Kotlin or powerful enums in Swift).
Go to my website for more information, code examples, and articles:
● https://resocoder.com
Follow me on social media:
● / resocoder
● / resocoder
● / resocoder