Hatena::Groupruby

kdmsnrの日記

 | 

1000-01-05

Observer

12:41

class Employee
  def initialize(salary)
    @salary = salary
  end
  
  def update_salary=(new_salary)
    @salary = new_salary
      # ここで通知しないと!
      notify_observer
  end

  attr_accessor :observer
  def notify_observer
    # @observerが複数になってもOK
    @observer.update(self)  
  end
end
 |