Domain-Driven Design helps us write complex software.
At the heart of it lies the *domain model*, which is a conceptual model that incorporates both behavior and data.
Sounds complicated?
Let's explain with an example. 🧵
Suppose we want to build an eCommerce app.
To better understand this domain, we need to figure out:
- the entities we care about and their relationships
- the behaviour (or business logic) for manipulating them
The end result may look like this:
In Dart, we can represent each entity as a simple model class.
As we define this, it helps to think about all the properties that we need to show in the UI:
In some cases we need both a model class and the logic for manipulating it.
For example, here's how we may define a shopping cart class along with some methods for mutating its items:
Note how the Cart class and MutableCart extension don't have dependencies to any objects that live outside the domain layer.
This makes them very easy to test:
Eric Evans has written an ENTIRE book about Domain-Driven Design, and it's well worth a read if you want to expand your skills as an application developer.
But here's a short summary that may help you take the first steps in this complex field:
Did you find this useful or have feedback to share? Let me know in the comments. 👇
And for more Flutter (and app development) tips, just follow me: @biz84
Happy coding!
• • •
Missing some Tweet in this thread? You can try to
force a refresh
If your users speak another language, you’ll need to localize your Flutter app 🗺
Here’s how to setup Flutter app localizations in just 5 minutes, using code generation.
Also covered: template vs non-template files and synthetic vs non-synthetic package. 👀
🧵
1️⃣ As a first step, we need to add the required packages to the pubspec.yaml file.
2️⃣ Create l10n.yaml at the root
✔️ arb-dir is the input folder where Flutter will look for the localized strings
✔️ output-dir is where the localizations classes will be generated
✔️ template-arb-file is the main template that contains a description for each localized message
What's the difference between errors and exceptions in Flutter?
→ Errors are programmer mistakes. They are fatal and we should not try to recover from them
→ Exceptions are failure conditions that are out of our control. We should handle them and recover gracefully
Thread 🧵
Errors are fatal and when they happen the program *cannot* recover normally.
→ we want to discover (and fix) them as early as possible in the development process
→ we should track them in production using a crash reporting solution, so that we can measure impact and severity