{"id":7958,"date":"2024-10-03T12:25:25","date_gmt":"2024-10-03T10:25:25","guid":{"rendered":"https:\/\/oopm.org\/?page_id=7958"},"modified":"2025-01-08T13:54:30","modified_gmt":"2025-01-08T12:54:30","slug":"17-3-1-the-alarm-example","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=7958","title":{"rendered":"18.3.1 The alarm example"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages7958&print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/pdf.png\" alt=\"image_pdf\" title=\"View PDF\" \/><\/a><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages7958&print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<style>\n#XXX_17_3 {\n  width: 40%;\n  padding-left: 15px;\n  margin-left: 15px;\n  float: right;\n  background-color: lightgray;\n font-size: 0.8em; \n}\n<\/style>\n<div id=\"XXX_17_3\">In order to simplify this first example, we do not represent the subject and observer aspects as aspects in the form of objects as in the previous sections. We give an example of this later in this section.<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The fire alarm is represented by an object of class <code>Alarm<\/code>, a subclass of <code>Subject<\/code>. The fire station, center owner, and shops are represented by instances of class <code>Stakeholder<\/code> which in turn is a subclass of <code>Observer<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AlarmSystem: <strong>obj<\/strong>\n   <strong>class<\/strong> Stakeholder(id: <strong>var<\/strong> String): Observer\n      ObservedSubject::&lt; ShoppingMall.Alarm\n      notify::&lt;\n          theSubject.whatWentWrong\n          ...\n      setUp:\n         ShoppingMall.fireAlarm.subscribe(this(StakeHolder))\n   FireStation: <strong>obj<\/strong> Stakeholder(\"FireStation\")\n   CenterOwner: <strong>obj<\/strong> Stakeholder(\"CenterOwner\")\n   ShoppingMall: <strong>obj<\/strong>\n      <strong>class<\/strong> Alarm(id: <strong>var<\/strong> String): Subject\n         whatWentWrong::\n            \" - smoke detected\\n\".print\n         alert:\n            notifyObservers\n      fireAlarm: <strong>obj<\/strong> Alarm(\"fireAlarm\")\n      aSensor: <strong>obj<\/strong> Sensor\n         ...; fireAlarm.alert; ...\n      ShopA: <strong>obj<\/strong> StakeHolder(\"ShopA\")\n      ShopB: <strong>obj<\/strong> StakeHolder(\"ShopB\")\n      ShopC: <strong>obj<\/strong> StakeHolder(\"ShopC\")\n      setUp:\n         ShopA.setUp\n         ShopB.setUp\n         ShopC.setUp\n   FireStation.setUp\n   CenterOwner.setUp\n   ShoppingMall.setUp<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>AlarmSystem<\/code> has a class <code>StakeHolder<\/code> that is a subclass of <code>Observer<\/code>.\n<ul class=\"wp-block-list\">\n<li>It has an <code>id<\/code> identifying the <code>Observer<\/code>.<\/li>\n\n\n\n<li>It makes further binding of <code>notify<\/code>, which invokes <code>theSubject.whatWentWrong<\/code>. The dots (<code>'...'<\/code>) indicates that some further actions may be needed. We discuss that at the end of this section.<\/li>\n\n\n\n<li>It makes a further binding of class <code>ObservedSubject<\/code> to <code>Alarm<\/code>. <\/li>\n\n\n\n<li>Note that <code>theSubject<\/code> (the parameter of <code>notify<\/code>) is of type <code>ObservedSubject<\/code>, and since it is bound to <code>Alarm<\/code>, the method <code>whatWentWrong<\/code> may be invoked.<\/li>\n\n\n\n<li>It has a method <code>setUp<\/code>, which invokes <code>ShoppingMall.fireAlarm.subscribe(this(StakeHolder))<\/code> and thereby makes <code>this(StakeHolder)<\/code> subscribe to events from <code>fireAlarm<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>The <code>AlarmSystem<\/code> has <code>Observer<\/code> objects <code>FireStation<\/code>, and <code>CenterOwner<\/code>, which are declared as instances of class <code>StakeHolder<\/code>.<\/li>\n\n\n\n<li>The <code>AlarmSystem<\/code> has a singular object <code>ShoppingMall<\/code>.\n<ul class=\"wp-block-list\">\n<li>It has a local class <code>Alarm<\/code>, which has an <code>id<\/code> identifying the alarm.\n<ul class=\"wp-block-list\">\n<li>It has a method <code>whatWentWrong<\/code> that may supply information to an <code>Observer<\/code> when notified.<\/li>\n\n\n\n<li>It has a method <code>alert<\/code> that is invoked by a fire censor in case a fire is detected.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>It has an object <code>fireAlarm<\/code> that is declared as an instance of class <code>Alarm<\/code>.<\/li>\n\n\n\n<li>It has a local object <code>aSensor<\/code>, which is an instance of class <code>Sensor<\/code> (not shown).<\/li>\n\n\n\n<li>It has local objects <code>ShopA<\/code>, <code>ShopB<\/code>, and <code>ShopC<\/code> representing three shops in the mall.<\/li>\n\n\n\n<li>It has method <code>setUp<\/code>, which invokes <code>setUp<\/code> for the three <code>Shop<\/code> objects and thereby makes them subscribe to events from the <code>fireAlarm<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Finally, the <code>AlarmSystem<\/code> invokes <code>setUp<\/code> for the <code>FireStation<\/code>, <code>CenterOwner<\/code> and <code>ShoppingMall<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In the example we have shown just one instance of a a <code>Sensor<\/code> object &#8211; in practice there may be many sensors in a shopping mall. We have not described how a <code>Sensor<\/code> object is activated to invoke <code>fireAlaram.alert<\/code> &#8211; this depends on the actual sensor hardware.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next diagram illustrates the situation where the subject <code>fireAlarm<\/code> has references to all the <code>Observers<\/code>, and the argument, <code>theSubject<\/code> of invocations of <code>notify<\/code> on an <code>Observer<\/code> refers to the <code>fireAlarm<\/code> object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>ShoppingMall<\/code> is an example of composition where <code>fireAlarm<\/code>, <code>aSensor<\/code>, <code>ShopA<\/code>, <code>ShopB<\/code> and <code>ShopC<\/code> are components being parts of the <code>ShoppingMall<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"900\" height=\"472\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/SubjectObserverAlarm-3.jpg\" alt=\"\" class=\"wp-image-10588\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/SubjectObserverAlarm-3.jpg 900w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/SubjectObserverAlarm-3-300x157.jpg 300w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/SubjectObserverAlarm-3-768x403.jpg 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Stakeholder<\/code> objects subscribe to events from the <code>fireAlarm<\/code>. This includes the <code>fireStation<\/code>, the <code>centerOwner<\/code>, and the shop stake holders:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"696\" height=\"356\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/fireAlarmOSD-1-1.jpg\" alt=\"\" class=\"wp-image-10123\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/fireAlarmOSD-1-1.jpg 696w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/fireAlarmOSD-1-1-300x153.jpg 300w\" sizes=\"(max-width: 696px) 100vw, 696px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Fire sensors located at places in the shopping center are represented by objects of class <code>Sensor<\/code>. When a sensor detects a fire, the corresponding <code>Sensor<\/code> object invoke <code>fireAlarm.alert<\/code>, which then invokes <code>notifyObservers<\/code>, which in turn invoke <code>notify<\/code> on all <code>Stakeholder<\/code> objects. This is illustrated by the following OSD, however, just showing one <code>Sensor<\/code> object.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"859\" height=\"532\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/fireAlarmOSD-2-1.jpg\" alt=\"\" class=\"wp-image-10125\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/fireAlarmOSD-2-1.jpg 859w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/fireAlarmOSD-2-1-300x186.jpg 300w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/12\/fireAlarmOSD-2-1-768x476.jpg 768w\" sizes=\"(max-width: 859px) 100vw, 859px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>notify<\/code> invocations all invoke <code>whatWentWong<\/code> on the <code>fireAlarm<\/code>, but this is not shown in the above diagram.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the above example, the <code>fireAlarm<\/code> is the only subject being observed. It is of course possible to add more <code>fireAlarm<\/code> objects at different places in the shopping center or at other locations. The <code>FireStation<\/code> will then observe all the <code>fireAlarms<\/code> whereas the shops and owner of a given shopping center only observe the alarms in that center.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Connections to the physical shopping center<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As mentioned in the start of this section, a notification of an observer may involve more action than described in the further binding of <code>notify<\/code> in class <code>StakeHolder<\/code>, since the different stakeholders may need to be informed in different ways.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For the <code>FireStation<\/code>, an alarm may be activated in the living room of the fire fighters, the address of the <code>ShoppingMall<\/code> must be communicated to the GPS in the fire engines, etc. For the <code>ShopOwner<\/code>, an sms may have to sent to the shop owner. For the shops, the owner and personel of a shop must be informed, etc. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As an example we may add an <code>inner<\/code> to <code>invoke<\/code> in <code>StakeHolder<\/code> and introduce a further binding of <code>invoke<\/code> in <code>CenterOwner<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AlarmSystem: <strong>obj<\/strong>\n   <strong>class<\/strong> Stakeholder(id: <strong>var<\/strong> String): Observer\n      ObservedSubject::&lt; Alarm \n      notify::&lt;\n          theSubject.whatWentWrong\n          inner(notify)\n      -\"-\n   -\"-\n   CenterOwner: <strong>obj<\/strong> Stakeholder(\"CenterOwner\")\n      notify::&lt;\n          -- send sms to center owner<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We have just inserted a comment about sending an sms to the owner of the center. In order to do that, we need an object that is connected to a real mobile phone device. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Remember that the objects in the example are representations of the real physical phenomena and their connection to these depends on the details of how the <code>AlarmSystem<\/code> is connected to the physical shopping mall. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<div style=\"display:flex; gap:10px;justify-content:center\" class=\"wps-pgfw-pdf-generate-icon__wrapper-frontend\">\n\t\t<a  href=\"https:\/\/oopm.org?action=genpdf&amp;id=7958\" class=\"pgfw-single-pdf-download-button\" ><img src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-generator-for-wp\/admin\/src\/images\/PDF_Tray.svg\" title=\"Generate PDF\" style=\"width:auto; height:45px;\"><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>In order to simplify this first example, we do not represent the subject and observer aspects as aspects in the form of objects as in the previous sections. We give an example of this later in this section. The fire alarm is represented by an object of class Alarm, a subclass of Subject. The fire [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":7529,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-7958","page","type-page","status-publish","hentry"],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/7958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7958"}],"version-history":[{"count":37,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/7958\/revisions"}],"predecessor-version":[{"id":10891,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/7958\/revisions\/10891"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/7529"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}