Controller for MVC?

  • Thread starter Hugh Sasse Staff Elec Eng
  • Start date
H

Hugh Sasse Staff Elec Eng

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.
 
J

Joel VanderWerf

Hugh said:
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
 
H

Hugh Sasse Staff Elec Eng

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top