Can the Single Responsibility Principle Be Applied Objectively? Yes
darrencauthon.posterous.com1 pointsby darrencauthon0 comments
goto fail;
goto fail;
if (error_of_sixth_kind) goto fail;
The_truly_important_code_handling_non_erroneous_case post.publish Date.now
than post.publish
When the publishing will only happen now? def publish(time, updated_by)
self.update publish_at: time, updated_by: updated_by
end
And so on, and so on. The dependencies have to be passed to the object, so every dependency flows up to become dependency on any object that uses it. And since having method calls like ".publish(Date.now, CurrentUser.name)" everywhere really stinks for readability and DRY, and since I can't make Date.now a constructor requirement to create a Post, I always found myself having to do this (in C#): public class PostPublisher
private IDate date;
private ICurrentUser;
public PostPublisher(IDate date, ICurrentUser){
this.date = date;
this.currentUser = currentUser;
}
public void Publish(post){
post.updated_by = currentUser.name;
post.published_on = date.now();
// save????
}
}
... and let the IoC container wire this sort of stuff up. Dependencies tied to this operation are isolated (as well as every other operation). But UGH, is this any better? So many classes and LOC just to do simple things.