Object-Oriented Controllers

241 views
Skip to first unread message

Avdi Grimm

unread,
Apr 30, 2012, 9:28:00 PM4/30/12
to objects-...@googlegroups.com
Several people have asked me what what I think truly object-oriented
controllers would look like. I haven't had time to write down my
ideas, but I feel like now I don't have to because Jon Leighton has
nailed it:

https://github.com/jonleighton/focused_controller

I've seen a few whacks at this problem involving things like DSLs for
setting up different contexts for different actions, but they rubbed
me the wrong way. If two different actions require two different sets
of helper methods, they should be two different objects.

Check out the README, it makes a great case for representing separate
actions as separate objects, possibly sharing common inheritance or
mixins.

I'm sure some people will be repelled by the verbosity of it, but I
suspect that it wouldn't be hard to apply some minimal DSL sugar which
preserved the semantics while cutting down on the need to type "class"
over and over.

Anyway, I'm excited to see this.

--
Avdi Grimm
http://avdi.org

I only check email twice a day. to reach me sooner, go to
http://awayfind.com/avdi

Felix Schäfer

unread,
May 1, 2012, 4:05:51 AM5/1/12
to objects-...@googlegroups.com
On Tue, May 1, 2012 at 3:28 AM, Avdi Grimm <avdi....@gmail.com> wrote:
> Jon Leighton has
> nailed it:
>
> https://github.com/jonleighton/focused_controller

IIRC he presented them at the Railsberry, I'll post the link to the
video here as soon it's available.

Felix

Kris Leech

unread,
Feb 13, 2013, 5:50:26 PM2/13/13
to objects-...@googlegroups.com, felix.s...@googlemail.com
I've been playing with using focused_controller tonight, its been a nice experience. Because actions are classes, not methods, it means that the listener passed to a service object is not a controller exposing public callback methods, which are potentially mappable from routing.

James Deville

unread,
Feb 14, 2013, 5:54:21 PM2/14/13
to objects-...@googlegroups.com, av...@avdi.org
I'd be interested in knowing people's thoughts on the Objectify pattern that James Golick uses/promotes with https://github.com/bitlove/objectify and http://jamesgolick.com/2012/5/22/objectify-a-better-way-to-build-rails-applications.html. I actually found that to be really appealing as it feels like it promotes more domain objects than "action" objects. I haven't had a chance to try either of them yet, so I don't know how the feel to use :|

Jim

Perry Smith

unread,
Feb 18, 2013, 12:15:24 PM2/18/13
to objects-...@googlegroups.com, av...@avdi.org
I need to read and play with these new ideas.

The thing I'm doing in my latest project is a half-ass morph of some of these concepts.  The reason for the morph is mostly due to growing into the solution rather than starting out with a new style directly.

I have a normal Rails controllers but the actions are trivial:

  def show
    respond_with(create_presenter(:which_fileset, GetWhichFilesets.new(params)))
  end

The presenter is a Keynote presenter (which has been discussed in this forum) and GetWhichFilesets is a class in app/actions.  The app/actions and app/entities are concepts stolen from Obvious.  I don't have any app/entities yet.

At the top of the controller I have

respond_to :html, :json 

and then put the to_json inside the presenter.  I really want each URL to be able to respond via HTML and via JSON.

So far, this is working out well for me.

The one "oh dear" I had is realizing that the action classes are verbs and not nouns.  One person on the net commented that when he does that, it tends to cause those classes to really have a focused single responsibility which seems to be true for me as well.  For me, it is easier to ask "is this part of <verb>?" than it is to ask "is this part of <noun>?"


--
You received this message because you are subscribed to the Google Groups "Objects on Rails" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objects-on-rai...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages