Carpe Noctem
Carpe Noctem

Reputation: 13

Flutter Clean Architecture

which part of file structure we should do processes of fromJson and toJson? Is it business or data layer?

I created entity class on business layer and an entity model created on data layer which extends entity.

I tried to building clean architecture on my project and watching some tutorials and reading blogs but I'm confused.

I hope I explain my question clearly.

Regards

Upvotes: 1

Views: 137

Answers (1)

Affan Minhas
Affan Minhas

Reputation: 567

For the purpose of clean architecture, the fromJson and toJson methods should typically be implemented in the data layer. Let's take a look on it.

Business Layer (Domain Layer):

  • The business layer contains the core logic of your application like what will happen when click on button.
  • Entities defined in the business layer should be pure representations of your domain concepts, without any knowledge of how they're persisted or serialized.

Data Layer (Repository Layer):

  • The data is responsible for fetching, storing and managing your data.
  • In data layer you would typically implement methods for serializing and deserializing data, such as fromJson and toJson.

You can follow the architecture as:

/lib
  /data
    - entity_model.dart
    - repository.dart
  /domain
    - entity.dart
    - use_case.dart
  /presentation
    - screen.dart

Upvotes: 1

Related Questions