ResoCoder / flutter-tdd-clean-architecture-course

https://resocoder.com/flutter-clean-architecture-tdd/
1.99k stars 623 forks source link

Share the same entity between two features #42

Open resfandiari opened 3 years ago

resfandiari commented 3 years ago

Great course, thanks a lot. How can I share an entity class between two features that use the same entity?

nvtanhh commented 3 years ago

The same question.

jttuboi commented 2 years ago

@resfandiari @nvtanhh Hi, I had this same question before and I found 4 ways:

Doing this, you isolate the domain in one place. I like this way because you concentrate the business rules and in theory, it needs to be one. It has two difficulties with it. One it's the data folder, so I did the same to that domain folder.

features/feature_1/presentation/... feature_2/presentation/... domain/entities/... data/...

The second difficulty is the massive quantity of use cases will concentrate in the folder. For each feature is added, the use cases will send to domain folder and grow a lot. Visually, you will concentrate a lot of files in one folder. However, I don't see this as disadvantaged because you can use the use_case in any features. domain/entities/... domain/use_cases/... It has an alternative only to create the entities folder, and the use_cases folder it created on features folder, but it's a bit strange to split the domain folder.

Well in the end, all of this is about organize your folder project. Find one it fits for your project and use it and be happy =).

Edit: if you read the comment: https://github.com/ResoCoder/flutter-tdd-clean-architecture-course/issues/23 the mikeandersen explains about the DDD approach used by resocoder in another project.