Code Monkey home page Code Monkey logo

Comments (2)

mattia-battiston avatar mattia-battiston commented on June 22, 2024

@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.

markosski avatar markosski commented on June 22, 2024

Thanks, this is helpful.

from clean-architecture-example.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.