class OrderSend
this observer pattern provides reusability class that helps to produce a dynamic pricing strategy for all the products every time the order is confirmed.
Public Class Methods
new()
click to toggle source
this method initializes the observer array to store the observable objects
# File lib/pricing_observer.rb, line 5 def initialize @observers=[] end
Public Instance Methods
add_observer(observer)
click to toggle source
adds the observable objects into class
# File lib/pricing_observer.rb, line 10 def add_observer(observer) @observers << observer end
delete_observer(observer)
click to toggle source
deletes the observable objects from the class
# File lib/pricing_observer.rb, line 15 def delete_observer(observer) @observers.delete(observer) end
notify_observers(check_store)
click to toggle source
notify's the observer when an desired condition is triggered
# File lib/pricing_observer.rb, line 20 def notify_observers(check_store) @observers.each do |observer| puts "Notifying" observer.pricing_by_hit(check_store) puts "Notified the observer" end end