Question

When providing a business logic method to get a domain entity, should the parameter accept an object or an ID? For example, should we do this:

public Foo GetItem(int id) {}

or this:

public Foo GetItem(Foo foo) {}

I believe in passing objects around, in their entirety, but what about this case where we're getting an object and we only know the ID? Should the caller create an empty Foo and set the ID, or should it just pass the ID to the method? Since the incoming Foo will be empty, except for the ID, I don't see the benefit of the caller having to create a Foo and set its ID when it could just send the ID to the GetItem() method.

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top