Class: OrderSend
- Inherits:
-
Object
- Object
- OrderSend
- Defined in:
- lib/pricing_observer.rb
Overview
this observer pattern provides reusability class that helps to produce a dynamic pricing strategy for all the products every time the order is confirmed.
Instance Method Summary collapse
-
#add_observer(observer) ⇒ Object
adds the observable objects into class.
-
#delete_observer(observer) ⇒ Object
deletes the observable objects from the class.
-
#initialize ⇒ OrderSend
constructor
this method initializes the observer array to store the observable objects.
-
#notify_observers(check_store) ⇒ Object
notify’s the observer when an desired condition is triggered.
Constructor Details
#initialize ⇒ OrderSend
this method initializes the observer array to store the observable objects
5 6 7 |
# File 'lib/pricing_observer.rb', line 5 def initialize @observers=[] end |
Instance Method Details
#add_observer(observer) ⇒ Object
adds the observable objects into class
10 11 12 |
# File 'lib/pricing_observer.rb', line 10 def add_observer(observer) @observers << observer end |
#delete_observer(observer) ⇒ Object
deletes the observable objects from the class
15 16 17 |
# File 'lib/pricing_observer.rb', line 15 def delete_observer(observer) @observers.delete(observer) end |
#notify_observers(check_store) ⇒ Object
notify’s the observer when an desired condition is triggered
20 21 22 23 24 25 26 |
# 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 |