Member-only story
Better Domain Modeling With Dartz And Equatable
Part of OOP modeling is setting up the right domain layer structure through implementing interfaces.
It can become easier if the Dartz package for functional programming is used to make implementing exceptions easier and if we use the Equatable package to make implementing models easier.
Why Dartz
Why Dartz or functional programming in the first place? Because, I can then use something like this:
Future<Either<RepoException, IModel>> getItem(int id);
And use an Either to ask for a future back, in this case a Model type or an Exception due to it failing, rather than a lot more boilerplate via try and catch statements.
That usage is typically found in the interfaces in the domain layer and the implementation in the data layer.
The other package, Equatable is used in Value object implementations such as immutable models.
Why Equatable
Why Equatable and not Built Value or Freezed? Both Built Value and Freezed require code generation. Whereas if I manually implement serializable, I can use Equatable instead. So let me show you the serializable implementation.