tags:

views:

32

answers:

1

A question about the flow of information in an object oriented construction, e.g. from controller to repository.

Should the objects passed always be in the model or should we allow smaller parts of information to travel?

What would you recommend? What factors decide the approach?

E.g. something like

Controller:
    string alias = "alpha";
    bool aliasExists = Repository.CheckIfAliasExists(alias)
Repository:
    bool CheckIfAliasExists(string alias);

or something like

Controller:
    string alias = "alpha";
    Member member = Repository.GetMemberByAlias(alias);
    bool aliasExists = member != null;
Repository:
    Member GetMemberByAlias(string alias);
+1  A: 

This is a pretty subjective subject, but I think the decision needs to boil down to two ideas: the performance of retrieving an entire object only for the purposes of determining existence, and the idea of allowing object-specific information to reach a greater scope.

Some will argue that allowing the application to make greater use of this identifying information increases your chances of bypassing the object model altogether, but I generally err on the side of performance in these instances.

My specific advice is to go with the former approach (though don't invalidate the latter, either).

Adam Robinson