Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share the same entity between two features #42

Open
resfandiari opened this issue May 16, 2021 · 2 comments
Open

Share the same entity between two features #42

resfandiari opened this issue May 16, 2021 · 2 comments

Comments

@resfandiari
Copy link

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

@nvtanhh
Copy link

nvtanhh commented Jul 21, 2021

The same question.

@jttuboi
Copy link

jttuboi commented Jan 2, 2022

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

  • you store the entity in a feature and use it in any features pointing to this feature which stored.
    ex: you have an entity X in feature that edit it. You use normally. And you create a new feature which list them, so you reuse the same entity from the previous feature.
    Because this entity is shared between 2 features, you can choose, or put the entity in the first feature created, or put the entity in the important feature. I don't like this alternative, you are accessing the content of another feature and it's strange.

  • you create a share folder for entities.
    ex: features/shared/entities/X.dart
    In this way, you can reuse this entity without access another feature. The problem of this, every time you need to reuse an entity, you must move the entity to shared folder.

  • you create a unique domain folder.
    ex:
    features/feature_1/presentation/...
    /data/...
    feature_2/presentation/...
    /data/...
    domain/entities/...
    /repositories/...

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.

  • the last one, the features are separated inside of presentation folder, domain folder and data folder.
    ex:
    presentation/feature_1/...
    presentation/feature_2/...
    domain/entities/...
    domain/use_cases/feature_1/...
    domain/use_cases/feature_2/...
    data/feature_1/...
    data/feature_2/...

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: #23
the mikeandersen explains about the DDD approach used by resocoder in another project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants