DDD is a mapping of your customer’s vocabulary to your design. Your client (hopefully) is talking about users applying for jobs, not an integer identifier associated with another integer identifier. Try to stay as close as possible to the real world if this does not become a burden.
By transferring the entire entity, you can immediately use the entity without first creating it.
Therefore, stick to entities if you do not have a situation where you often only have an ID. This usually happens when you are dealing with external systems such as web services. In this case, you can create a method overload that takes an identifier. This overload must verify the identifier, build the object, and invoke the overload that takes the object.
public void Apply(int jobId, int userId) {
Again: try to avoid such overloads as much as possible, unless you are dealing with external systems that return only IDs.
In terms of coding, entities are also better than integers. An integer can be any integer value, so you have to check it wherever you use it. Your factories are responsible for creating the right objects, and your (domain) logic should keep your entities in an acceptable state. Thus, the use of the object is completely safe and does not require much verification.
Niels van der rest
source share