Re:Applying the Unix Philosophy to Object-Oriented Design
by swanson on Wednesday November 28, 2012 @10:17AM
(#4842897)
Maybe it's because I've been reading about DCI lately, but I think this example could go even further in moving business logic out of the AR model.
Something like that? Too Java-y? Feedback appreciated :)
[ Parent
| on HN ]
Re:Applying the Unix Philosophy to Object-Oriented Design
by r00k on Wednesday November 28, 2012 @10:26AM
(#4842944)
Interesting approach. It'd be a bit surprising in a Rails app, however, since models usually handle their own validation.
That said, the fact that GuestBookEntry doesn't have validation as a concern does make it simpler.
I might refactor to something like this if a particular model had extremely complicated validation logic, but wouldn't ever do this as a first pass.
Re:Applying the Unix Philosophy to Object-Oriented Design
by swanson on Wednesday November 28, 2012 @10:31AM
(#4842975)
I think in general models can handle their own validation (especially if you use AR), but I guess the difference is that these validations hit external "services", instead of like a :max_length validation.
I agree on the first pass comment - I imagine that the user stories went something like:
* v1 - An anon user can post to the guestbook
* v2 - Guestbook comments are checked for spam
* v3 - Post guestbook comments to twitter for Web 2.0-ness
And this is the refactored version after v3
Re:Applying the Unix Philosophy to Object-Oriented Design
by vidarh on Wednesday November 28, 2012 @11:26AM
(#4843318)
Not too Java-y, but too "DataMapper-y" for most Rails devs, I think (the pattern, not the ORM - the Ruby DataMapper ORM implements the ActiveRecord pattern, though DataMapper 2 actually finally will implement DataMapper)
EDIT: This is an interesting overview of where DataMapper 2 is going as a parallel to your example: http://solnic.eu/2012/01/10/ruby-datamapper-status.html