{"id":1502,"date":"2023-10-13T16:06:45","date_gmt":"2023-10-13T14:06:45","guid":{"rendered":"https:\/\/epicmarketing.co.il\/notebook\/?p=1502"},"modified":"2023-10-14T20:49:54","modified_gmt":"2023-10-14T18:49:54","slug":"the-observer-design-pattern","status":"publish","type":"post","link":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/","title":{"rendered":"The Observer Design Pattern"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Observer Design Pattern \u05de\u05d2\u05d3\u05d9\u05e8 \u05e2\u05d1\u05d5\u05e8\u05e0\u05d5 \u05d9\u05d7\u05e1\u05d9\u05dd \u05e9\u05dc \u05d9\u05d7\u05d9\u05d3 \u05dc\u05e8\u05d1\u05d9\u05dd \u05d1\u05d9\u05df \u05d0\u05d5\u05d1\u05d9\u05d9\u05e7\u05d8\u05d9\u05dd, \u05db\u05da \u05e9\u05db\u05e9\u05de\u05ea\u05d1\u05e6\u05e2 \u05e9\u05d9\u05e0\u05d5\u05d9 \u05d1\u05d0\u05d5\u05d1\u05d9\u05d9\u05e7\u05d8 \u05e9\u05d0\u05e0\u05d7\u05e0\u05d5 \u05e2\u05d5\u05e7\u05d1\u05d9\u05dd \u05d0\u05d7\u05e8\u05d9\u05d5, \u05db\u05dc \u05d4\u05ea\u05dc\u05d5\u05d9\u05d9\u05dd \u05d1\u05d5 \u05d9\u05e7\u05d1\u05dc\u05d5 \u05d4\u05d5\u05d3\u05e2\u05d4 \u05d5\u05d9\u05ea\u05e2\u05d3\u05db\u05e0\u05d5.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u05de\u05d4 \u05d6\u05d4 Observer Design Pattern?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u05e0\u05e0\u05d9\u05d7 \u05e9\u05d9\u05e9 \u05dc\u05db\u05dd \u05e2\u05e8\u05d5\u05e5 \u05d9\u05d5\u05d8\u05d9\u05d5\u05d1. \u05d1\u05db\u05dc \u05e4\u05e2\u05dd \u05db\u05e9\u05d0\u05ea\u05dd \u05de\u05e2\u05dc\u05d9\u05dd \u05d5\u05d9\u05d3\u05d0\u05d5, \u05db\u05dc \u05d4\u05de\u05e0\u05d5\u05d9\u05d9\u05dd \u05e9\u05dc\u05db\u05dd \u05de\u05e7\u05d1\u05dc\u05d9\u05dd \u05d4\u05d5\u05d3\u05e2\u05d4. \u05d4\u05e2\u05e8\u05d5\u05e5 \u05e9\u05dc\u05db\u05dd &quot;\u05e0\u05e6\u05e4\u05d4&quot; \u05e2\u05dc \u05d9\u05d3\u05d9 \u05d4\u05de\u05e0\u05d5\u05d9\u05d9\u05dd \u05e9\u05d4\u05dd &quot;\u05e6\u05d5\u05e4\u05d9\u05dd&quot;. \u05db\u05e9\u05de\u05e2\u05dc\u05d9\u05dd \u05e1\u05e8\u05d8\u05d5\u05df \u05d7\u05d3\u05e9, \u05db\u05dc\u05d5\u05de\u05e8 \u05db\u05e9\u05d9\u05e9 \u05e9\u05d9\u05e0\u05d5\u05d9 \u05d1&quot;\u05de\u05e6\u05d1&quot; \u05e9\u05dc \u05d4\u05e2\u05e8\u05d5\u05e5, \u05db\u05dc \u05d4\u05de\u05e0\u05d5\u05d9\u05d9\u05dd observers \u05de\u05e7\u05d1\u05dc\u05d9\u05dd \u05d4\u05d5\u05d3\u05e2\u05d4.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern-1024x512.jpg\" alt=\"\" class=\"wp-image-1503\" srcset=\"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern-1024x512.jpg 1024w, https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern-300x150.jpg 300w, https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern-768x384.jpg 768w, https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern.jpg 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">\u05d0\u05dd \u05e0\u05e4\u05e8\u05e7 \u05d0\u05ea \u05d4\u05d3\u05d5\u05d2\u05de\u05d0 \u05de\u05dc\u05de\u05e2\u05dc\u05d4 \u05dc\u05de\u05d5\u05e0\u05d7\u05d9\u05dd \u05e9\u05dc Observer Design Pattern, \u05d9\u05e9 \u05dc\u05e0\u05d5:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Subject<\/strong> &#8211; \u05e2\u05e8\u05d5\u05e5 \u05d4\u05d9\u05d5\u05d8\u05d9\u05d5\u05d1 &#8211; \u05de\u05d4 \u05e9\u05d0\u05e0\u05d7\u05e0\u05d5 \u05e6\u05d5\u05e4\u05d9\u05dd \u05d1\u05e9\u05d9\u05e0\u05d5\u05d9\u05d9\u05dd \u05e9\u05dc\u05d5. \u05d4\u05d5\u05d0 \u05de\u05d7\u05d6\u05d9\u05e7 \u05e8\u05e9\u05d9\u05de\u05d4 \u05e9\u05dc \u05de\u05e0\u05d5\u05d9\u05d9\u05dd observers \u05d5\u05de\u05d5\u05d3\u05d9\u05e2 \u05dc\u05d4\u05dd \u05db\u05e9\u05d9\u05e9 \u05d1\u05d5 \u05e9\u05d9\u05e0\u05d5\u05d9.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Observers<\/strong> &#8211; \u05d4\u05de\u05e0\u05d5\u05d9\u05d9\u05dd &#8211; \u05d4\u05dd \u05de\u05e0\u05d5\u05d9\u05d9\u05dd \u05dc-<strong>Subject<\/strong> \u05d5\u05e8\u05d5\u05e6\u05d9\u05dd \u05dc\u05d1\u05e6\u05e2 \u05d0\u05d9\u05d6\u05d4 \u05e4\u05e2\u05d5\u05dc\u05d4 \u05db\u05d0\u05e9\u05e8 \u05d9\u05d4\u05d9\u05d4 \u05d1\u05d5 \u05e9\u05d9\u05e0\u05d5\u05d9.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u05d1\u05de\u05d5\u05e9\u05d2\u05d9\u05dd \u05e9\u05dc \u05e2\u05d5\u05dc\u05dd \u05d4\u05e4\u05d9\u05ea\u05d5\u05d7, \u05d9\u05e9 \u05dc\u05e0\u05d5:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Subject<\/strong> &#8211; \u05d4-class \u05e9\u05d9\u05e9 \u05d1\u05d5 \u05e4\u05d5\u05e0\u05e7\u05e6\u05d9\u05d5\u05ea \u05e9\u05dc add, remove \u05e9\u05dc observers, \u05d5\u05e4\u05d5\u05e0\u05e7\u05e6\u05d9\u05d4 \u05e9\u05de\u05d5\u05e6\u05d9\u05d0\u05d4 \u05d0\u05ea \u05d4\u05d4\u05d5\u05d3\u05e2\u05d5\u05ea \u05dc\u05de\u05e0\u05d5\u05d9\u05d9\u05dd \u05db\u05e9\u05d9\u05e9 \u05e9\u05d9\u05e0\u05d5\u05d9 \u05d1\u05de\u05e6\u05d1.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Observer<\/strong> &#8211; \u05dc-classes \u05d4\u05d0\u05dc\u05d4 \u05d9\u05e9 \u05e4\u05d5\u05e0\u05e7\u05e6\u05d9\u05d4 \u05e9\u05e0\u05e7\u05e8\u05d0\u05ea \u05db\u05d0\u05e9\u05e8 \u05d9\u05e9 \u05e9\u05d9\u05e0\u05d5\u05d9 \u05d1-<strong>Subject<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u05d3\u05d5\u05d2\u05de\u05d0 &#8211; \u05ea\u05d7\u05e0\u05ea \u05de\u05d6\u05d2 \u05d0\u05d5\u05d9\u05e8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u05e0\u05e7\u05d7 \u05dc\u05d3\u05d5\u05d2\u05de\u05d0 \u05d0\u05e4\u05dc\u05d9\u05e7\u05e6\u05d9\u05d4 \u05e9\u05dc \u05de\u05d6\u05d2 \u05d0\u05d5\u05d9\u05e8 (subject). \u05d4\u05d0\u05e4\u05dc\u05d9\u05e7\u05e6\u05d9\u05d4 \u05d0\u05d5\u05e1\u05e4\u05ea \u05de\u05d9\u05d3\u05e2 \u05de\u05de\u05e1\u05e4\u05e8 \u05e1\u05e0\u05e1\u05d5\u05e8\u05d9\u05dd \u05d5\u05de\u05e6\u05d9\u05d2\u05d4 \u05d0\u05ea \u05de\u05d6\u05d2 \u05d4\u05d0\u05d5\u05d9\u05e8 \u05d4\u05de\u05e2\u05d5\u05d3\u05db\u05df.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u05d4\u05de\u05e9\u05ea\u05de\u05e9\u05d9\u05dd \u05d1\u05d0\u05e4\u05dc\u05d9\u05e7\u05e6\u05d9\u05d4 \u05de\u05e7\u05d1\u05dc\u05d9\u05dd \u05d4\u05ea\u05e8\u05e2\u05d5\u05ea (observers) \u05db\u05d0\u05e9\u05e8 \u05d9\u05e9 \u05ea\u05e0\u05d0\u05d9\u05dd \u05de\u05e1\u05d5\u05d9\u05d9\u05de\u05d9\u05dd \u05dc\u05de\u05d6\u05d2 \u05d4\u05d0\u05d5\u05d9\u05e8. \u05dc\u05de\u05e9\u05dc:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u05e6\u05e4\u05d5\u05d9 \u05d2\u05e9\u05dd.<\/li>\n\n\n\n<li>\u05d4\u05d8\u05de\u05e4\u05e8\u05d8\u05d5\u05e8\u05d4 \u05d9\u05d5\u05e8\u05d3\u05ea \u05de\u05ea\u05d7\u05ea \u05dc-0 \u05de\u05e2\u05dc\u05d5\u05ea.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u05e2\u05dd Observer Design Pattern, \u05d4\u05d0\u05e4\u05dc\u05d9\u05e7\u05e6\u05d9\u05d4 \u05dc\u05d0 \u05e6\u05e8\u05d9\u05db\u05d4 \u05dc\u05d3\u05e2\u05ea \u05d0\u05ea \u05d4\u05e4\u05e8\u05d8\u05d9\u05dd \u05e9\u05dc \u05d4\u05de\u05e9\u05ea\u05de\u05e9\u05d9\u05dd. \u05d4\u05d9\u05d0 \u05e9\u05d5\u05dc\u05d7\u05ea \u05d0\u05ea \u05d4\u05de\u05d9\u05d3\u05e2 \u05dc\u05db\u05dc \u05de\u05d9 \u05e9\u05e8\u05e9\u05d5\u05dd \u05dc\u05e9\u05d9\u05e8\u05d5\u05ea \u05e9\u05dc\u05d4.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern1-1024x512.jpg\" alt=\"\" class=\"wp-image-1506\" srcset=\"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern1-1024x512.jpg 1024w, https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern1-300x150.jpg 300w, https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern1-768x384.jpg 768w, https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern1.jpg 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">\u05d4\u05d7\u05dc\u05e7\u05d9\u05dd \u05e9\u05dc \u05d4\u05e4\u05e2\u05d5\u05dc\u05d4 \u05d4\u05dd:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Weather Station App (Subject)<\/strong> &#8211; \u05d0\u05d5\u05e1\u05e4\u05ea \u05d0\u05ea \u05d4\u05de\u05d9\u05d3\u05e2, \u05de\u05d5\u05d3\u05d9\u05e2\u05d4 \u05dc\u05de\u05d9 \u05e9\u05e8\u05e9\u05d5\u05dd \u05d0\u05dc\u05d9\u05d4.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Notifications\/Alerts (Observers)<\/strong> &#8211; \u05de\u05d7\u05db\u05d9\u05dd \u05dc\u05e2\u05d3\u05db\u05d5\u05e0\u05d9\u05dd, \u05de\u05ea\u05d1\u05e6\u05e2\u05ea \u05e4\u05e2\u05d5\u05dc\u05d4 \u05db\u05d0\u05e9\u05e8 \u05de\u05d2\u05d9\u05e2 \u05d4\u05e2\u05d3\u05db\u05d5\u05df.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u05e0\u05e8\u05d0\u05d4 \u05d0\u05d9\u05da \u05d6\u05d4 \u05d9\u05e8\u05d0\u05d4 \u05d1\u05e7\u05d5\u05d3.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; highlight: [1,30]; title: ; notranslate\" title=\"\">\nclass WeatherStation {\n    constructor() {\n        this.observers = &#x5B;];\n        this.weatherData = { temperature: 0, humidity: 0, pressure: 0 };\n    }\n\n    addObserver(observer) {\n        this.observers.push(observer);\n    }\n\n    removeObserver(observer) {\n        const index = this.observers.indexOf(observer);\n        if (index &gt; -1) {\n            this.observers.splice(index, 1);\n        }\n    }\n\n    notifyObservers() {\n        for (const observer of this.observers) {\n            observer.update(this.weatherData);\n        }\n    }\n\n    setWeatherData(newWeatherData) {\n        this.weatherData = { ...this.weatherData, ...newWeatherData };\n        this.notifyObservers();\n    }\n}\n\nclass WeatherAlert {\n    constructor(alertType) {\n        this.alertType = alertType;\n    }\n\n    update(weatherData) {\n        \/\/ Basic demonstration: you might have more complex logic here in a real app\n        console.log(`Weather Alert &#x5B;${this.alertType}]: \n           New weather data received!`, weatherData);\n    }\n}\n\n\/\/ Example usage\nconst weatherStation = new WeatherStation();\n\nconst rainAlert = new WeatherAlert(&quot;Rain&quot;);\nconst freezeAlert = new WeatherAlert(&quot;Freeze&quot;);\n\nweatherStation.addObserver(rainAlert);\nweatherStation.addObserver(freezeAlert);\n\nweatherStation.setWeatherData({ temperature: 25, humidity: 80, pressure: 1013 });\n\/\/ Weather Alert &#x5B;Rain]: New weather data received! \n\/\/ { temperature: 25, humidity: 80, pressure: 1013 }\n\/\/ Weather Alert &#x5B;Freeze]: New weather data received! \n\/\/ { temperature: 25, humidity: 80, pressure: 1013 }\n\nweatherStation.setWeatherData({ temperature: -1, humidity: 80, pressure: 1010 });\n\/\/ Weather Alert &#x5B;Rain]: New weather data received! \n\/\/ { temperature: -1, humidity: 80, pressure: 1010 }\n\/\/ Weather Alert &#x5B;Freeze]: New weather data received! \n\/\/ { temperature: -1, humidity: 80, pressure: 1010 }\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">\u05de\u05d4 \u05d9\u05e9 \u05dc\u05e0\u05d5 \u05e4\u05d4?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\">WeatherStation (Subject)<\/span><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>addObserver(observer) &#8211; \u05de\u05d5\u05e1\u05d9\u05e3 observer \u05e9\u05d9\u05e7\u05d1\u05dc \u05d0\u05ea \u05d4\u05d4\u05d5\u05d3\u05e2\u05d5\u05ea.<\/li>\n\n\n\n<li>removeObserver(observer) &#8211; \u05de\u05d5\u05e8\u05d9\u05d3 observer  \u05de\u05e8\u05e9\u05d9\u05de\u05ea \u05de\u05e7\u05d1\u05dc\u05d9 \u05d4\u05d4\u05d5\u05d3\u05e2\u05d5\u05ea.<\/li>\n\n\n\n<li>notifyObservers &#8211; \u05de\u05d5\u05d3\u05d9\u05e2 \u05dc\u05db\u05dc \u05d4\u05e8\u05e9\u05d5\u05de\u05d9\u05dd \u05e2\u05dc \u05d4\u05e9\u05d9\u05e0\u05d5\u05d9\u05d9\u05dd.<\/li>\n\n\n\n<li>setWeatherData(newWeatherData) &#8211; \u05de\u05e2\u05d3\u05db\u05df \u05d0\u05ea \u05d4\u05de\u05d9\u05d3\u05e2 \u05d5\u05e9\u05d5\u05dc\u05d7 \u05d4\u05d5\u05d3\u05e2\u05d4 \u05dc\u05e0\u05e8\u05e9\u05de\u05d9\u05dd.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\">WeatherAlert (Observer)<\/span><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>update(weatherData) &#8211; \u05de\u05d1\u05e6\u05e2 \u05e4\u05e2\u05d5\u05dc\u05d4 \u05e2\u05dc \u05e1\u05de\u05da \u05d4\u05de\u05d9\u05d3\u05e2 \u05e9\u05d4\u05ea\u05e7\u05d1\u05dc. \u05d1\u05d0\u05e4\u05dc\u05d9\u05e7\u05e6\u05d9\u05d4 \u05d0\u05de\u05d9\u05ea\u05d9\u05ea, \u05e4\u05d4 \u05d4\u05d9\u05ea\u05d4 \u05e4\u05e2\u05d5\u05dc\u05d4 \u05e9\u05dc \u05d4\u05e6\u05d2\u05d4 \u05d0\u05d5 \u05e9\u05dc\u05d9\u05d7\u05d4 \u05e9\u05dc \u05d4\u05de\u05d9\u05d3\u05e2, \u05dc\u05de\u05e9\u05dc.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u05db\u05e9\u05d9\u05e9 \u05e7\u05e8\u05d9\u05d0\u05d4 \u05dc-setWeatherData \u05d1\u05ea\u05d5\u05da WeatherStation \u05de\u05ea\u05e2\u05d3\u05db\u05df \u05d4-weatherData \u05e9\u05de\u05d5\u05d3\u05d9\u05e2 \u05dc\u05db\u05dc \u05d4\u05e0\u05e8\u05e9\u05de\u05d9\u05dd \u05e9\u05dc\u05d5 \u05e2\u05dc \u05d4\u05de\u05d9\u05d3\u05e2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u05d3\u05d5\u05d2\u05de\u05d0 \u05e0\u05d5\u05e1\u05e4\u05ea &#8211; \u05d0\u05ea\u05e8 \u05de\u05db\u05d9\u05e8\u05d5\u05ea<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u05e0\u05e7\u05d7 \u05dc\u05d3\u05d5\u05d2\u05de\u05d0 \u05d0\u05ea\u05e8 \u05de\u05db\u05d9\u05e8\u05d5\u05ea. \u05e0\u05e0\u05d9\u05d7 \u05e9\u05d9\u05e9 \u05dc\u05e0\u05d5 \u05de\u05e1\u05e4\u05e8 \u05e7\u05d5\u05de\u05e4\u05d5\u05e0\u05e0\u05d8\u05d5\u05ea \u05e9\u05e6\u05e8\u05d9\u05db\u05d5\u05ea \u05dc\u05d4\u05ea\u05e2\u05d3\u05db\u05df \u05db\u05d0\u05e9\u05e8 \u05d4\u05d2\u05d5\u05dc\u05e9 \u05de\u05db\u05e0\u05d9\u05e1 \u05de\u05d5\u05e6\u05e8 \u05d7\u05d3\u05e9 \u05dc\u05e2\u05d2\u05dc\u05d4, \u05dc\u05de\u05e9\u05dc \u05e1\u05d9\u05db\u05d5\u05dd \u05e1\u05db\u05d5\u05dd \u05d4\u05e8\u05db\u05d9\u05e9\u05d4 \u05d1\u05e2\u05d2\u05dc\u05d4, \u05e8\u05e9\u05d9\u05de\u05ea \u05d4\u05de\u05d5\u05e6\u05e8\u05d9\u05dd \u05dc\u05e8\u05db\u05d9\u05e9\u05d4, \u05d1\u05d0\u05e0\u05e8\u05d9\u05dd \u05e4\u05e8\u05e1\u05d5\u05de\u05d9\u05d9\u05dd \u05d5\u05e2\u05d5\u05d3.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u05e0\u05e8\u05d0\u05d4 \u05d3\u05d5\u05d2\u05de\u05d0 \u05dc\u05e7\u05d5\u05d3 \u05d0\u05e0\u05d2\u05d5\u05dc\u05e8\u05d9.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\">Cart Service (Subject)<\/span><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u05d1-service \u05d0\u05e0\u05d7\u05e0\u05d5 \u05de\u05e0\u05d4\u05dc\u05d9\u05dd \u05d0\u05ea \u05d4\u05de\u05d5\u05e6\u05e8\u05d9\u05dd \u05e9\u05e0\u05de\u05e6\u05d0\u05d9\u05dd \u05d1\u05e2\u05d2\u05dc\u05d4 \u05d5\u05de\u05d7\u05d6\u05d9\u05e7\u05d9\u05dd \u05e8\u05e9\u05d9\u05de\u05d4 \u05e9\u05dc observers \u05e9\u05e6\u05e8\u05d9\u05da \u05dc\u05d4\u05d5\u05d3\u05d9\u05e2 \u05dc\u05d4\u05dd \u05db\u05e9\u05d9\u05e9 \u05d4\u05d5\u05e1\u05e4\u05d4 \u05e9\u05dc \u05de\u05d5\u05e6\u05e8.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nimport { Injectable } from &#039;@angular\/core&#039;;\nimport { BehaviorSubject, Observable } from &#039;rxjs&#039;;\n\n@Injectable({\n  providedIn: &#039;root&#039;\n})\nexport class CartService {\n  private cartItems: any&#x5B;] = &#x5B;];\n  private cartSubject = new BehaviorSubject(this.cartItems);\n\n  addToCart(item: any): void {\n    this.cartItems.push(item);\n    this.cartSubject.next(this.cartItems);\n  }\n\n  getCartObservable(): Observable&lt;any&#x5B;]&gt; {\n    return this.cartSubject.asObservable();\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\">Cart Component (Observer)<\/span><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u05d4\u05e7\u05d5\u05de\u05e4\u05d5\u05e0\u05e0\u05d8\u05d4 \u05d4\u05d6\u05d0\u05ea \u05de\u05e6\u05d9\u05d2\u05d4 \u05d0\u05ea \u05ea\u05d5\u05db\u05df \u05d4\u05e2\u05d2\u05dc\u05d4 \u05d5\u05de\u05ea\u05e2\u05d3\u05db\u05e0\u05ea \u05db\u05d0\u05e9\u05e8 \u05de\u05d5\u05db\u05e0\u05e1 \u05d0\u05dc\u05d9\u05d4 \u05de\u05d5\u05e6\u05e8 \u05d7\u05d3\u05e9.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nimport { Component, OnInit, OnDestroy } from &#039;@angular\/core&#039;;\nimport { CartService } from &#039;.\/cart.service&#039;;\nimport { Subscription } from &#039;rxjs&#039;;\n\n@Component({\n  selector: &#039;app-cart&#039;,\n  template: `\n    &lt;h2&gt;Your Cart&lt;\/h2&gt;\n    &lt;ul&gt;\n      &lt;li *ngFor=&quot;let item of cartItems&quot;&gt;{{ item.name }}&lt;\/li&gt;\n    &lt;\/ul&gt;\n  `\n})\nexport class CartComponent implements OnInit, OnDestroy {\n  cartItems: any&#x5B;] = &#x5B;];\n  cartSubscription!: Subscription;\n\n  constructor(private cartService: CartService) {}\n\n  ngOnInit(): void {\n    this.cartSubscription = this.cartService.getCartObservable().subscribe(items =&gt; {\n      this.cartItems = items;\n    });\n  }\n\n  ngOnDestroy(): void {\n    this.cartSubscription.unsubscribe();\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\">Add Product Component<\/span><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u05d4\u05e7\u05d5\u05de\u05e4\u05d5\u05e0\u05e0\u05d8\u05d4 \u05d4\u05d6\u05d0\u05ea \u05de\u05d0\u05e4\u05e9\u05e8\u05ea \u05dc\u05de\u05e9\u05ea\u05de\u05e9\u05d9\u05dd \u05dc\u05d4\u05d5\u05e1\u05d9\u05e3 \u05de\u05d5\u05e6\u05e8\u05d9\u05dd.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nimport { Component } from &#039;@angular\/core&#039;;\nimport { CartService } from &#039;.\/cart.service&#039;;\n\n@Component({\n  selector: &#039;app-add-product&#039;,\n  template: `\n    &lt;button (click)=&quot;addItem()&quot;&gt;Add Item to Cart&lt;\/button&gt;\n  `\n})\nexport class AddProductComponent {\n  constructor(private cartService: CartService) {}\n\n  addItem(): void {\n    const newItem = { name: `Item ${Math.floor(Math.random() * 100)}` };\n    this.cartService.addToCart(newItem);\n  }\n}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u05dc\u05de\u05d4 \u05dc\u05d4\u05e9\u05ea\u05de\u05e9 \u05d1-Observer Design Pattern?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Decoupling &#8211; \u05d4-subject \u05dc\u05d0 \u05e6\u05e8\u05d9\u05da \u05dc\u05d3\u05e2\u05ea \u05db\u05dc\u05d5\u05dd \u05e2\u05dc \u05d4\u05e2\u05d5\u05e7\u05d1\u05d9\u05dd \u05d0\u05d7\u05e8\u05d9\u05d5.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Dynamic Relationships &#8211; \u05d0\u05e4\u05e9\u05e8 \u05dc\u05d4\u05d5\u05e1\u05d9\u05e3 \u05d5\u05dc\u05d4\u05d5\u05e8\u05d9\u05d3 Observers \u05d1\u05d6\u05de\u05df \u05e8\u05d9\u05e6\u05d4 \u05d1\u05dc\u05d9 \u05dc\u05e9\u05e0\u05d5\u05ea \u05d0\u05ea \u05d4\u05d0\u05d5\u05d1\u05d9\u05d9\u05e7\u05d8\u05d9\u05dd.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Broadcast Communication &#8211; \u05e9\u05d9\u05e0\u05d5\u05d9\u05d9\u05dd \u05d1\u05de\u05d9\u05d3\u05e2 \u05d1\u05d0\u05d5\u05d1\u05d9\u05d9\u05e7\u05d8 \u05d0\u05d7\u05d3 \u05de\u05e9\u05d5\u05d3\u05e8\u05d9\u05dd \u05dc\u05d4\u05e8\u05d1\u05d4 \u05d0\u05d5\u05d1\u05d9\u05d9\u05e7\u05d8\u05d9\u05dd \u05d0\u05d7\u05e8\u05d9\u05dd.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u05d3\u05d5\u05d2\u05de\u05d0 \u05e0\u05d5\u05e1\u05e4\u05ea &#8211; \u05d0\u05d9\u05de\u05d5\u05ea \u05de\u05e9\u05ea\u05de\u05e9<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u05e0\u05e8\u05d0\u05d4 \u05d3\u05d5\u05d2\u05de\u05d0 \u05d0\u05e0\u05d2\u05d5\u05dc\u05e8\u05d9\u05ea \u05e0\u05d5\u05e1\u05e4\u05ea \u05e9\u05d1\u05d4 \u05e0\u05d1\u05d7\u05df authentication \u05e9\u05dc \u05de\u05e9\u05ea\u05de\u05e9. \u05db\u05d0\u05e9\u05e8 \u05de\u05e9\u05ea\u05de\u05e9 \u05de\u05ea\u05d7\u05d1\u05e8 \u05dc\u05d7\u05e9\u05d1\u05d5\u05df \u05e9\u05dc\u05d5 \u05d9\u05d4\u05d9\u05d5 \u05de\u05e1\u05e4\u05e8 \u05e7\u05d5\u05de\u05e4\u05d5\u05e0\u05e0\u05d8\u05d5\u05ea \u05e9\u05d9\u05e6\u05d8\u05e8\u05db\u05d5 \u05dc\u05e7\u05d1\u05dc \u05d0\u05ea \u05d4\u05de\u05d9\u05d3\u05e2 \u05d4\u05d6\u05d4 \u05db\u05de\u05d5 \u05ea\u05e4\u05e8\u05d9\u05d8 \u05e8\u05d0\u05e9\u05d9, \u05ea\u05e4\u05e8\u05d9\u05d8 \u05e6\u05d3 \u05d5\u05db\u05d5'<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\">AuthService (Subject)<\/span><\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nimport { Injectable } from &#039;@angular\/core&#039;;\nimport { BehaviorSubject, Observable } from &#039;rxjs&#039;;\n\n@Injectable({\n  providedIn: &#039;root&#039;\n})\nexport class AuthService {\n  private isAuthenticatedSubject = new BehaviorSubject&lt;boolean&gt;(false);\n  isAuthenticated$ = this.isAuthenticatedSubject.asObservable();\n\n  login(): void {\n    \/\/ Authentication logic (e.g., API call) would be here...\n    this.isAuthenticatedSubject.next(true);\n  }\n\n  logout(): void {\n    \/\/ Logout logic would be here...\n    this.isAuthenticatedSubject.next(false);\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\">HeaderComponent (Observer)<\/span><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u05d4\u05e7\u05d5\u05de\u05e4\u05d5\u05e0\u05e0\u05d8\u05d4 \u05d4\u05d6\u05d0\u05ea \u05de\u05e6\u05d9\u05d2\u05d4 \u05de\u05d9\u05d3\u05e2 \u05dc\u05d2\u05d5\u05dc\u05e9 \u05d1-header \u05d5\u05de\u05ea\u05e2\u05d3\u05db\u05e0\u05ea \u05db\u05d0\u05e9\u05e8 \u05d4\u05d2\u05d5\u05dc\u05e9 \u05e0\u05db\u05e0\u05e1 \u05dc\u05d7\u05e9\u05d1\u05d5\u05df.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nimport { Component, OnInit, OnDestroy } from &#039;@angular\/core&#039;;\nimport { AuthService } from &#039;.\/auth.service&#039;;\nimport { Subscription } from &#039;rxjs&#039;;\n\n@Component({\n  selector: &#039;app-header&#039;,\n  template: `\n    &lt;ng-container *ngIf=&quot;isAuthenticated; else loggedOutTemplate&quot;&gt;\n      &lt;p&gt;Welcome, User!&lt;\/p&gt;\n    &lt;\/ng-container&gt;\n    &lt;ng-template #loggedOutTemplate&gt;\n      &lt;p&gt;Please log in.&lt;\/p&gt;\n    &lt;\/ng-template&gt;\n  `\n})\nexport class HeaderComponent implements OnInit, OnDestroy {\n  isAuthenticated: boolean = false;\n  private authSubscription!: Subscription;\n\n  constructor(private authService: AuthService) {}\n\n  ngOnInit(): void {\n    this.authSubscription = this.authService.isAuthenticated$.subscribe(\n      isAuthenticated =&gt; {\n        this.isAuthenticated = isAuthenticated;\n      }\n    );\n  }\n\n  ngOnDestroy(): void {\n    this.authSubscription.unsubscribe();\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\">LoginFormComponent<\/span><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u05d4\u05e7\u05d5\u05de\u05e4\u05d5\u05e0\u05e0\u05d8\u05d4 \u05de\u05d0\u05e4\u05e9\u05e8\u05ea \u05db\u05e0\u05d9\u05e1\u05d4 \u05d5\u05d9\u05e6\u05d9\u05d0\u05d4 \u05de\u05d4\u05d7\u05e9\u05d1\u05d5\u05df.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nimport { Component } from &#039;@angular\/core&#039;;\nimport { AuthService } from &#039;.\/auth.service&#039;;\n\n@Component({\n  selector: &#039;app-login-form&#039;,\n  template: `\n    &lt;button (click)=&quot;login()&quot;&gt;Login&lt;\/button&gt;\n    &lt;button (click)=&quot;logout()&quot;&gt;Logout&lt;\/button&gt;\n  `\n})\nexport class LoginFormComponent {\n  constructor(private authService: AuthService) {}\n\n  login(): void {\n    this.authService.login();\n  }\n\n  logout(): void {\n    this.authService.logout();\n  }\n}\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern2-1024x512.jpg\" alt=\"\" class=\"wp-image-1515\" srcset=\"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern2-1024x512.jpg 1024w, https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern2-300x150.jpg 300w, https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern2-768x384.jpg 768w, https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern2.jpg 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u05d1\u05d3\u05e8\u05da \u05d4\u05d6\u05d0\u05ea \u05db\u05dc \u05e7\u05d5\u05de\u05e4\u05d5\u05e0\u05e0\u05d8\u05d4 \u05e9\u05e6\u05e8\u05d9\u05db\u05d4 \u05d9\u05db\u05d5\u05dc\u05d4 \u05dc\u05d2\u05e9\u05ea \u05dc\u05de\u05e6\u05d1 \u05d4-login \u05e9\u05dc \u05d4\u05de\u05e9\u05ea\u05de\u05e9.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Observer Design Pattern \u05de\u05d2\u05d3\u05d9\u05e8 \u05e2\u05d1\u05d5\u05e8\u05e0\u05d5 \u05d9\u05d7\u05e1\u05d9\u05dd \u05e9\u05dc \u05d9\u05d7\u05d9\u05d3 \u05dc\u05e8\u05d1\u05d9\u05dd \u05d1\u05d9\u05df \u05d0\u05d5\u05d1\u05d9\u05d9\u05e7\u05d8\u05d9\u05dd, \u05db\u05da \u05e9\u05db\u05e9\u05de\u05ea\u05d1\u05e6\u05e2 \u05e9\u05d9\u05e0\u05d5\u05d9 \u05d1\u05d0\u05d5\u05d1\u05d9\u05d9\u05e7\u05d8 \u05e9\u05d0\u05e0\u05d7\u05e0\u05d5 \u05e2\u05d5\u05e7\u05d1\u05d9\u05dd \u05d0\u05d7\u05e8\u05d9\u05d5, \u05db\u05dc \u05d4\u05ea\u05dc\u05d5\u05d9\u05d9\u05dd \u05d1\u05d5 \u05d9\u05e7\u05d1\u05dc\u05d5 \u05d4\u05d5\u05d3\u05e2\u05d4 \u05d5\u05d9\u05ea\u05e2\u05d3\u05db\u05e0\u05d5. \u05de\u05d4 \u05d6\u05d4 Observer Design Pattern? \u05e0\u05e0\u05d9\u05d7 \u05e9\u05d9\u05e9 \u05dc\u05db\u05dd \u05e2\u05e8\u05d5\u05e5 \u05d9\u05d5\u05d8\u05d9\u05d5\u05d1. \u05d1\u05db\u05dc \u05e4\u05e2\u05dd \u05db\u05e9\u05d0\u05ea\u05dd \u05de\u05e2\u05dc\u05d9\u05dd \u05d5\u05d9\u05d3\u05d0\u05d5, \u05db\u05dc \u05d4\u05de\u05e0\u05d5\u05d9\u05d9\u05dd \u05e9\u05dc\u05db\u05dd \u05de\u05e7\u05d1\u05dc\u05d9\u05dd \u05d4\u05d5\u05d3\u05e2\u05d4. \u05d4\u05e2\u05e8\u05d5\u05e5 \u05e9\u05dc\u05db\u05dd &quot;\u05e0\u05e6\u05e4\u05d4&quot; \u05e2\u05dc \u05d9\u05d3\u05d9 \u05d4\u05de\u05e0\u05d5\u05d9\u05d9\u05dd \u05e9\u05d4\u05dd &quot;\u05e6\u05d5\u05e4\u05d9\u05dd&quot;. \u05db\u05e9\u05de\u05e2\u05dc\u05d9\u05dd \u05e1\u05e8\u05d8\u05d5\u05df [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[47],"tags":[],"class_list":["post-1502","post","type-post","status-publish","format-standard","hentry","category-design-patterns","entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The Observer Design Pattern - Code Notebook<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/\" \/>\n<meta property=\"og:locale\" content=\"he_IL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Observer Design Pattern - Code Notebook\" \/>\n<meta property=\"og:description\" content=\"The Observer Design Pattern \u05de\u05d2\u05d3\u05d9\u05e8 \u05e2\u05d1\u05d5\u05e8\u05e0\u05d5 \u05d9\u05d7\u05e1\u05d9\u05dd \u05e9\u05dc \u05d9\u05d7\u05d9\u05d3 \u05dc\u05e8\u05d1\u05d9\u05dd \u05d1\u05d9\u05df \u05d0\u05d5\u05d1\u05d9\u05d9\u05e7\u05d8\u05d9\u05dd, \u05db\u05da \u05e9\u05db\u05e9\u05de\u05ea\u05d1\u05e6\u05e2 \u05e9\u05d9\u05e0\u05d5\u05d9 \u05d1\u05d0\u05d5\u05d1\u05d9\u05d9\u05e7\u05d8 \u05e9\u05d0\u05e0\u05d7\u05e0\u05d5 \u05e2\u05d5\u05e7\u05d1\u05d9\u05dd \u05d0\u05d7\u05e8\u05d9\u05d5, \u05db\u05dc \u05d4\u05ea\u05dc\u05d5\u05d9\u05d9\u05dd \u05d1\u05d5 \u05d9\u05e7\u05d1\u05dc\u05d5 \u05d4\u05d5\u05d3\u05e2\u05d4 \u05d5\u05d9\u05ea\u05e2\u05d3\u05db\u05e0\u05d5. \u05de\u05d4 \u05d6\u05d4 Observer Design Pattern? \u05e0\u05e0\u05d9\u05d7 \u05e9\u05d9\u05e9 \u05dc\u05db\u05dd \u05e2\u05e8\u05d5\u05e5 \u05d9\u05d5\u05d8\u05d9\u05d5\u05d1. \u05d1\u05db\u05dc \u05e4\u05e2\u05dd \u05db\u05e9\u05d0\u05ea\u05dd \u05de\u05e2\u05dc\u05d9\u05dd \u05d5\u05d9\u05d3\u05d0\u05d5, \u05db\u05dc \u05d4\u05de\u05e0\u05d5\u05d9\u05d9\u05dd \u05e9\u05dc\u05db\u05dd \u05de\u05e7\u05d1\u05dc\u05d9\u05dd \u05d4\u05d5\u05d3\u05e2\u05d4. \u05d4\u05e2\u05e8\u05d5\u05e5 \u05e9\u05dc\u05db\u05dd &quot;\u05e0\u05e6\u05e4\u05d4&quot; \u05e2\u05dc \u05d9\u05d3\u05d9 \u05d4\u05de\u05e0\u05d5\u05d9\u05d9\u05dd \u05e9\u05d4\u05dd &quot;\u05e6\u05d5\u05e4\u05d9\u05dd&quot;. \u05db\u05e9\u05de\u05e2\u05dc\u05d9\u05dd \u05e1\u05e8\u05d8\u05d5\u05df [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Notebook\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-13T14:06:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-14T18:49:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern-1024x512.jpg\" \/>\n<meta name=\"author\" content=\"kerendanino\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u05e0\u05db\u05ea\u05d1 \u05e2\u05dc \u05d9\u05d3\" \/>\n\t<meta name=\"twitter:data1\" content=\"kerendanino\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u05d6\u05de\u05df \u05e7\u05e8\u05d9\u05d0\u05d4 \u05de\u05d5\u05e2\u05e8\u05da\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u05d3\u05e7\u05d5\u05ea\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/\"},\"author\":{\"name\":\"kerendanino\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#\\\/schema\\\/person\\\/195dfc625818eadda7903d456890e24c\"},\"headline\":\"The Observer Design Pattern\",\"datePublished\":\"2023-10-13T14:06:45+00:00\",\"dateModified\":\"2023-10-14T18:49:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/\"},\"wordCount\":106,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/The-Observer-Design-Pattern-1024x512.jpg\",\"articleSection\":[\"Design Patterns\"],\"inLanguage\":\"he-IL\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/\",\"url\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/\",\"name\":\"The Observer Design Pattern - Code Notebook\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/The-Observer-Design-Pattern-1024x512.jpg\",\"datePublished\":\"2023-10-13T14:06:45+00:00\",\"dateModified\":\"2023-10-14T18:49:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/#breadcrumb\"},\"inLanguage\":\"he-IL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"he-IL\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/#primaryimage\",\"url\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/The-Observer-Design-Pattern.jpg\",\"contentUrl\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/The-Observer-Design-Pattern.jpg\",\"width\":1200,\"height\":600},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/the-observer-design-pattern\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The Observer Design Pattern\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#website\",\"url\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/\",\"name\":\"Code Notebook\",\"description\":\"Easy coding\",\"publisher\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"he-IL\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#organization\",\"name\":\"Code Notebook\",\"url\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"he-IL\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo-epic-marketing-05.png\",\"contentUrl\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo-epic-marketing-05.png\",\"width\":3626,\"height\":1942,\"caption\":\"Code Notebook\"},\"image\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#\\\/schema\\\/person\\\/195dfc625818eadda7903d456890e24c\",\"name\":\"kerendanino\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"he-IL\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/285cc9389c66aa46da1e26a474b1e90e9efaf3fa21f1b928cbd63ce5f0e89c63?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/285cc9389c66aa46da1e26a474b1e90e9efaf3fa21f1b928cbd63ce5f0e89c63?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/285cc9389c66aa46da1e26a474b1e90e9efaf3fa21f1b928cbd63ce5f0e89c63?s=96&d=mm&r=g\",\"caption\":\"kerendanino\"},\"url\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/author\\\/kerendanino\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The Observer Design Pattern - Code Notebook","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/","og_locale":"he_IL","og_type":"article","og_title":"The Observer Design Pattern - Code Notebook","og_description":"The Observer Design Pattern \u05de\u05d2\u05d3\u05d9\u05e8 \u05e2\u05d1\u05d5\u05e8\u05e0\u05d5 \u05d9\u05d7\u05e1\u05d9\u05dd \u05e9\u05dc \u05d9\u05d7\u05d9\u05d3 \u05dc\u05e8\u05d1\u05d9\u05dd \u05d1\u05d9\u05df \u05d0\u05d5\u05d1\u05d9\u05d9\u05e7\u05d8\u05d9\u05dd, \u05db\u05da \u05e9\u05db\u05e9\u05de\u05ea\u05d1\u05e6\u05e2 \u05e9\u05d9\u05e0\u05d5\u05d9 \u05d1\u05d0\u05d5\u05d1\u05d9\u05d9\u05e7\u05d8 \u05e9\u05d0\u05e0\u05d7\u05e0\u05d5 \u05e2\u05d5\u05e7\u05d1\u05d9\u05dd \u05d0\u05d7\u05e8\u05d9\u05d5, \u05db\u05dc \u05d4\u05ea\u05dc\u05d5\u05d9\u05d9\u05dd \u05d1\u05d5 \u05d9\u05e7\u05d1\u05dc\u05d5 \u05d4\u05d5\u05d3\u05e2\u05d4 \u05d5\u05d9\u05ea\u05e2\u05d3\u05db\u05e0\u05d5. \u05de\u05d4 \u05d6\u05d4 Observer Design Pattern? \u05e0\u05e0\u05d9\u05d7 \u05e9\u05d9\u05e9 \u05dc\u05db\u05dd \u05e2\u05e8\u05d5\u05e5 \u05d9\u05d5\u05d8\u05d9\u05d5\u05d1. \u05d1\u05db\u05dc \u05e4\u05e2\u05dd \u05db\u05e9\u05d0\u05ea\u05dd \u05de\u05e2\u05dc\u05d9\u05dd \u05d5\u05d9\u05d3\u05d0\u05d5, \u05db\u05dc \u05d4\u05de\u05e0\u05d5\u05d9\u05d9\u05dd \u05e9\u05dc\u05db\u05dd \u05de\u05e7\u05d1\u05dc\u05d9\u05dd \u05d4\u05d5\u05d3\u05e2\u05d4. \u05d4\u05e2\u05e8\u05d5\u05e5 \u05e9\u05dc\u05db\u05dd &quot;\u05e0\u05e6\u05e4\u05d4&quot; \u05e2\u05dc \u05d9\u05d3\u05d9 \u05d4\u05de\u05e0\u05d5\u05d9\u05d9\u05dd \u05e9\u05d4\u05dd &quot;\u05e6\u05d5\u05e4\u05d9\u05dd&quot;. \u05db\u05e9\u05de\u05e2\u05dc\u05d9\u05dd \u05e1\u05e8\u05d8\u05d5\u05df [&hellip;]","og_url":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/","og_site_name":"Code Notebook","article_published_time":"2023-10-13T14:06:45+00:00","article_modified_time":"2023-10-14T18:49:54+00:00","og_image":[{"url":"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern-1024x512.jpg","type":"","width":"","height":""}],"author":"kerendanino","twitter_card":"summary_large_image","twitter_misc":{"\u05e0\u05db\u05ea\u05d1 \u05e2\u05dc \u05d9\u05d3":"kerendanino","\u05d6\u05de\u05df \u05e7\u05e8\u05d9\u05d0\u05d4 \u05de\u05d5\u05e2\u05e8\u05da":"3 \u05d3\u05e7\u05d5\u05ea"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/#article","isPartOf":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/"},"author":{"name":"kerendanino","@id":"https:\/\/epicmarketing.co.il\/notebook\/#\/schema\/person\/195dfc625818eadda7903d456890e24c"},"headline":"The Observer Design Pattern","datePublished":"2023-10-13T14:06:45+00:00","dateModified":"2023-10-14T18:49:54+00:00","mainEntityOfPage":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/"},"wordCount":106,"commentCount":0,"publisher":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/#organization"},"image":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/#primaryimage"},"thumbnailUrl":"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern-1024x512.jpg","articleSection":["Design Patterns"],"inLanguage":"he-IL","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/","url":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/","name":"The Observer Design Pattern - Code Notebook","isPartOf":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/#website"},"primaryImageOfPage":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/#primaryimage"},"image":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/#primaryimage"},"thumbnailUrl":"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern-1024x512.jpg","datePublished":"2023-10-13T14:06:45+00:00","dateModified":"2023-10-14T18:49:54+00:00","breadcrumb":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/#breadcrumb"},"inLanguage":"he-IL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/"]}]},{"@type":"ImageObject","inLanguage":"he-IL","@id":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/#primaryimage","url":"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern.jpg","contentUrl":"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/10\/The-Observer-Design-Pattern.jpg","width":1200,"height":600},{"@type":"BreadcrumbList","@id":"https:\/\/epicmarketing.co.il\/notebook\/the-observer-design-pattern\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/epicmarketing.co.il\/notebook\/"},{"@type":"ListItem","position":2,"name":"The Observer Design Pattern"}]},{"@type":"WebSite","@id":"https:\/\/epicmarketing.co.il\/notebook\/#website","url":"https:\/\/epicmarketing.co.il\/notebook\/","name":"Code Notebook","description":"Easy coding","publisher":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/epicmarketing.co.il\/notebook\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"he-IL"},{"@type":"Organization","@id":"https:\/\/epicmarketing.co.il\/notebook\/#organization","name":"Code Notebook","url":"https:\/\/epicmarketing.co.il\/notebook\/","logo":{"@type":"ImageObject","inLanguage":"he-IL","@id":"https:\/\/epicmarketing.co.il\/notebook\/#\/schema\/logo\/image\/","url":"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/07\/logo-epic-marketing-05.png","contentUrl":"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/07\/logo-epic-marketing-05.png","width":3626,"height":1942,"caption":"Code Notebook"},"image":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/epicmarketing.co.il\/notebook\/#\/schema\/person\/195dfc625818eadda7903d456890e24c","name":"kerendanino","image":{"@type":"ImageObject","inLanguage":"he-IL","@id":"https:\/\/secure.gravatar.com\/avatar\/285cc9389c66aa46da1e26a474b1e90e9efaf3fa21f1b928cbd63ce5f0e89c63?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/285cc9389c66aa46da1e26a474b1e90e9efaf3fa21f1b928cbd63ce5f0e89c63?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/285cc9389c66aa46da1e26a474b1e90e9efaf3fa21f1b928cbd63ce5f0e89c63?s=96&d=mm&r=g","caption":"kerendanino"},"url":"https:\/\/epicmarketing.co.il\/notebook\/author\/kerendanino\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/posts\/1502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/comments?post=1502"}],"version-history":[{"count":9,"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/posts\/1502\/revisions"}],"predecessor-version":[{"id":1516,"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/posts\/1502\/revisions\/1516"}],"wp:attachment":[{"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/media?parent=1502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/categories?post=1502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/tags?post=1502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}