Controller for MVC?

Discussion in 'Ruby' started by Hugh Sasse Staff Elec Eng, Feb 1, 2005.

  1. It seems to me that some of the characteristics of the controller in MVC
    mirror those in delegator, or in some kind of bidirectional chain of
    responsibility in so far as they result in messages being passed
    through to the far side[1]. This is particularly the case when the
    main job of the controller is isolation between the view and the
    model.

    Is there a well known good way to provide this, since delegators
    seem to be unidirectional and so do chains of responsibility?
    I'm don't know how to phrase the search so that I get useful
    results -- I haven't been able to so far, anyway.

    Should I be looking at Needle to provide the isolation? I think I
    will want the controller to do some work, to enable the
    choice of view to be flexible. I'm thinking there is probably a way
    to write less code than to write all the controller's methods
    explicitly by hand, but method_missing() would need to do
    something different depending on which direction I'm going
    (View->Model, Model->view), which will need to be coded in the
    method name, I think.

    I suspect that I won't be able to use Observable because both sides
    observe and are observed by the controller, creating a loop.

    Hugh

    [1] Not in the Gary Larson sense, at least not until my code gets
    really weird.
    Hugh Sasse Staff Elec Eng, Feb 1, 2005
    #1
    1. Advertising

  2. Hugh Sasse Staff Elec Eng wrote:
    > I suspect that I won't be able to use Observable because both sides
    > observe and are observed by the controller, creating a loop.


    If you're considering obervable attributes (the poorly named
    "observable" on raa), then loops are fine. There's even an example with
    cycles:

    module CycleExample

    class Gossip
    attr_accessor :friends
    observable :news

    def initialize
    @friends = []
    @news = "No news."
    when_news CHANGES do |new_value|
    @friends.each {|friend| friend.news = new_value}
    end
    end
    end

    g = (0..8).collect {Gossip.new}

    # make a complex network with cycles

    g[0].friends = [g[1], g[2]]
    g[1].friends = [g[3], g[4]]
    g[2].friends = [g[4], g[5]]
    g[3].friends = [g[0]]
    g[4].friends = [g[2]]
    g[5].friends = [g[3], g[6]]
    g[6].friends = [] # doesn't tell anyone (not strongly connected)
    g[7].friends = [] # nobody tells g[7] (not connected at all)
    g[8].friends = [g[0]] # nobody tells g[8], but g[8] would tell g[0]

    g[0].news = "I've got a girl and Ruby is her name."

    puts (0..g.size-1).map {|i| "g[#{i}].news = #{g.news.inspect}"}

    # Output:
    # g[0].news = "I've got a girl and Ruby is her name."
    # g[1].news = "I've got a girl and Ruby is her name."
    # g[2].news = "I've got a girl and Ruby is her name."
    # g[3].news = "I've got a girl and Ruby is her name."
    # g[4].news = "I've got a girl and Ruby is her name."
    # g[5].news = "I've got a girl and Ruby is her name."
    # g[6].news = "I've got a girl and Ruby is her name."
    # g[7].news = "No news."
    # g[8].news = "No news."

    end
    Joel VanderWerf, Feb 1, 2005
    #2
    1. Advertising

  3. On Wed, 2 Feb 2005, Joel VanderWerf wrote:

    > Hugh Sasse Staff Elec Eng wrote:
    >> I suspect that I won't be able to use Observable because both sides
    >> observe and are observed by the controller, creating a loop.

    >
    > If you're considering obervable attributes (the poorly named "observable" on
    > raa), then loops are fine. There's even an example with cycles:
    >

    [nice example trimmed]

    Thank you, I'll follow that up.

    Hugh
    Hugh Sasse Staff Elec Eng, Feb 1, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VisionSet

    MVC: Controller for Swing

    VisionSet, Nov 5, 2003, in forum: Java
    Replies:
    1
    Views:
    463
    Harald Hein
    Nov 5, 2003
  2. VisionSet

    MVC - controller

    VisionSet, Sep 23, 2004, in forum: Java
    Replies:
    0
    Views:
    465
    VisionSet
    Sep 23, 2004
  3. VisionSet

    MVC - controller

    VisionSet, Sep 28, 2004, in forum: Java
    Replies:
    0
    Views:
    408
    VisionSet
    Sep 28, 2004
  4. =?Utf-8?B?TG9yZW56byBKaW1lbmV6?=

    Is MS silent about MVC-Page controller for ASP.NET 2.0

    =?Utf-8?B?TG9yZW56byBKaW1lbmV6?=, May 31, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    715
    bruce barker \(sqlwork.com\)
    May 31, 2006
  5. Michael Earls
    Replies:
    3
    Views:
    3,241
    MBUnit
    Mar 24, 2009
Loading...

Share This Page