<p>As an exercise for myself, I was translating a sample program into various languages.   Starting in C#, I had a visitor-pattern interface like so:</p>

<pre><code>interface Visitor
    {
        void Accept(Bedroom x);
        void Accept(Bathroom x);
        void Accept(Kitchen x);
        void Accept(LivingRoom x);
    }
</code></pre>

<p>Moving to ruby (or python, or whatever), I no longer get dispatch from the compiler based on type.  Should I do the dispatch in the visitor itself?</p>

<pre><code>class Cleaner

  def accept(x)
    acceptBedroom(x) if Bedroom === x
    acceptBathroom(x) if Bathroom === x
    acceptKitchen(x) if Kitchen===x
    acceptLivingRoom(x) if LivingRoom===x
  end

  ...
</code></pre>

<p>Or should I do the dispatch in the different specializaions of the room:</p>

<pre><code>class Bathroom&lt;Room
  def initialize(name)
    super(name)
  end
  def accept(visitor)
    visitor.acceptBathroom(self)
  end
end
</code></pre>

<p>Or is there another preferred idiom that is used in dynamic languages?</p>

[{'answer_id': 44362, 'author': 'Dillie-O', 'author_id': 71, 'author_profile': 'https://Stackoverflow.com/users/71', 'pm_score': 0, 'selected': False, 'text': "<p>It sounds to me that you'll want to handle two events:</p>\n\n<p>GotFocus: Will trigger when the textbox gains focus. You can store the initial value of the box.</p>\n\n<p>LostFocus: Will trigger when the textbox loses focus. At this point you can do your validation and decide if you want to roll back or not.</p>\n"}, {'answer_id': 47663, 'author': 'David Schmitt', 'author_id': 4918, 'author_profile': 'https://Stackoverflow.com/users/4918', 'pm_score': 3, 'selected': True, 'text': '<p>You can force the keyboard focus to stay on the <code>TextBox</code> by handling the <code>PreviewLostKeyBoardFocus</code> event like this:</p>\n<pre class="lang-xml prettyprint-override"><code>     &lt;TextBox PreviewLostKeyboardFocus=&quot;TextBox_PreviewLostKeyboardFocus&quot; /&gt; \n</code></pre>\n<pre class="lang-cs prettyprint-override"><code>     private void TextBox_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) {\n         e.Handled = true;\n     }\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/44337', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4540/']