Comments (2)
@martez81 you're right, I don't expose the database id as it only makes sense for the db and not for the other data providers. Ideally I'd use a natural identifier for the entities.
The example you mention makes perfect sense: if someone wants to update info of a user, I would look up that user in the database by something unique about them (e.g. by username, or by email address).
Having said that, I can mention another technique that I tried in the past but ended up not liking.
Say that we have an entity called User. In the database module you extend it and have UserInDb, which holds its databaseId. Now the other modules can still pass around an object of type User which knows nothing about databaseId, and only in the database module you cast it back to UserInDb.
As I said, this works, but I didn't like it very much as it relies on the casting of User to UserInDb, which might not be safe if the User object was created by a module other than the database. If possible, I'd keep looking up the user by a natural key.
from clean-architecture-example.
Thanks, this is helpful.
from clean-architecture-example.
Related Issues (10)
- Which layer should the transaction management be on? HOT 8
- [QUESTION] How to avoid duplicate interactor HOT 4
- Q: what layer should Gateway interface belong to? HOT 1
- "Use Case" Examples are leaking domain objects (entities) HOT 1
- Missing the last 'e'
- Creating war from root gradle script
- Unit tests
- This isn't clean
- Configuration of data providers?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clean-architecture-example.