Advertisement
PhilDrummer

Assignment_10 02 TEMPERATURE_SENSOR.e

Dec 16th, 2014
1,201
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. note
  2.     description: "Summary description for {TEMPERATURE_SENSOR}."
  3.     author: ""
  4.     date: "$Date$"
  5.     revision: "$Revision$"
  6.  
  7. class
  8.     TEMPERATURE_SENSOR
  9.  
  10. create
  11.     make
  12.  
  13. feature -- Initialization
  14.  
  15.     make
  16.             -- Creation procedure
  17.         do
  18.             create {V_LINKED_LIST [PROCEDURE[ANY, TUPLE[REAL_64]]]} on_temperature_change
  19.         end
  20.  
  21. feature -- Subscription
  22.  
  23.     register (a_procedure: PROCEDURE[ANY, TUPLE[REAL_64]])
  24.             -- Register a new observer.
  25.         require
  26.             a_procedure_exists: a_procedure /= void
  27.         do
  28.             if
  29.                 not on_temperature_change.has (a_procedure)
  30.             then
  31.                 on_temperature_change.extend_back (a_procedure)
  32.             end
  33.         ensure
  34.             a_procedure_exists: on_temperature_change.has (a_procedure)
  35.         end
  36.  
  37.     unregister (a_procedure: PROCEDURE[ANY, TUPLE[REAL_64]])
  38.             -- Unregister an existing observe-r.
  39.         require
  40.             a_procedure_exists: a_procedure /= void
  41.         do
  42.             if
  43.                 on_temperature_change.has (a_procedure)
  44.             then
  45.                 on_temperature_change.remove (a_procedure)
  46.             end
  47.         ensure
  48.             a_procedure_does_not_exist: not on_temperature_change.has (a_procedure)
  49.         end
  50.  
  51. feature -- Write / Set
  52.  
  53.     set_temperature (a_temperature: REAL_64)
  54.             -- Set the new temperature.
  55.         require
  56.             temperature_input_exists: a_temperature /= void
  57.         do
  58.             temperature := a_temperature
  59.             across
  60.                 on_temperature_change as i
  61.             loop
  62.                 i.item.call (temperature)
  63.             end
  64.         ensure
  65.             temperature_exists: temperature /= void
  66.             temperature_is_correct: temperature = a_temperature
  67.         end
  68.  
  69. feature -- Access
  70.  
  71.     temperature: REAL_64
  72.         -- Current temperature.
  73.  
  74.     on_temperature_change: V_LINKED_LIST [PROCEDURE[ANY, TUPLE[REAL_64]]]
  75.         -- Actions performed on temperature change.
  76.  
  77. end
Advertisement
RAW Paste Data Copied
Advertisement